KAMTOR.CPP
//
//+------------------------------------------------------------------+
//+ Program KAMTORUS.CPP, version 0.2                                +
//+ Plots *hundreds* of Kamtorus fractals.                           +
//+ (when you think it's all over... a new one is produced!)         +
//+                                                                  +
//+ By Ramiro Perez (Panama), RPEREZ@UTPVM1.BITNET                   +
//+ and Fausto A. A. Barbuto (Brazil), BJ06@C53000.PETROBRAS.ANRJ.BR +
//+ April 9, 1994.                                                   +
//+                                                                  +
//+ Press any key to stop execution or PAUSE to freeze.              +
//+ SVGA256 version; supports up to five video screens.              +
//+ Authorized version for spanky.triumf.ca site.                    +
//+------------------------------------------------------------------+
//
#include 
#include 
#include 
#include 
#include 
#include 
#include "Svga256.h"

int Vid;  //Global variable

int huge DetectSVGA256()
{
  printf("\nWhich video mode would you like to use? \n\n");
  printf(" 0 - 320x200x256\n");
  printf(" 1 - 640x400x256\n");
  printf(" 2 - 640x480x256\n");
  printf(" 3 - 800x600x256\n");
  printf(" 4 - 1024x768x256\n\n>");
  scanf("%d",&Vid);
  if((Vid<0) || (Vid)>4) Vid = 2;
  return Vid;
}

void main(void)
{
  int a, c, nx, ny;
  time_t t;
  unsigned long k;
  double an, can, san, can1, san1, e, r, ax, ay;
  double x, xa, x1, x2, x3, y, y1, y2, y3, rand1, rand2;
  int graphdriver=DETECT, graphmode;

  clrscr();
  printf("\n          Program KAMTORUS.CPP \n\n");
  installuserdriver("Svga256",DetectSVGA256);
  initgraph(&graphdriver,&graphmode,"C:\\BORLANDC\\BGI");

  if (Vid == 0) { nx = 160; ny = 100; ax =  200.; ay = ax;}
  if (Vid == 1) { nx = 320; ny = 200; ax =  300.; ay = ax;}
  if (Vid == 2) { nx = 320; ny = 240; ax =  400.; ay = ax;}
  if (Vid == 3) { nx = 400; ny = 300; ax =  750.; ay = ax;}
  if (Vid == 4) { nx = 512; ny = 359; ax = 1000.; ay = ax;}
  if ((Vid>4) || (Vid<0)) { nx = 320; ny = 240; ax = 400; ay = ax;}

  do {
    cleardevice();
    c = 1;
    srand((unsigned) time(&t));
    rand1 = random(20000);
    rand2 = random(20000);
    rand1 = 5.0e-5*rand1;
    rand2 = 5.0e-5*rand2;
    an = 10.0*(rand1-rand2);
    can = 0.99*cos(an);
    san = 0.99*sin(an);
    can1 = 1.01*cos(an);
    san1 = 1.01*sin(an);
    for (a=1;a<=256;a++) setpalette (a,(int)(0.0128*random(20000)));
    x3 = 0.01;
    y3 = 0.01;
    do {
      xa = x3*x3 - y3;
      x2 = x3*can1 + xa*san1;
      y2 = x3*san1 - xa*can1;
      x3 = x2;
      y3 = y2;
      x = x2;
      y = y2;
      a = 0;
      do {
	xa = x*x - y;
	x1 = x*can + xa*san;
	y1 = x*san - xa*can;
	x  = x1;
	y  = y1;
	a++;
	putpixel((int)(ax*x+nx),(int)(ay*y+ny),c);
      }  while ((fabs(x1)<=2.0e3) && (fabs(y1)<=2.0e3) && a<=100);
      e = e + 0.075;
      c = (int)e % 5 + 1;
    } while ((fabs(x2) <= 2.0e3) && (fabs(y2) <= 2.0e3));
//*
//  Change "k" to increase/decrease time delay between each plot.
//  In a DX2-66 k(max)=5000000 produces a time delay of 2-3 seconds.
//*
    for (k=0;k<=5000000;k++);
  } while (!kbhit());
  closegraph();
}