home *** CD-ROM | disk | FTP | other *** search
/ Rat's Nest 1 / ratsnest1.iso / prgmming / c / kamtor.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  3.4 KB  |  105 lines

  1. //
  2.  
  3. //+------------------------------------------------------------------+
  4.  
  5. //+ Program KAMTORUS.CPP, version 0.2                                +
  6.  
  7. //+ Plots *hundreds* of Kamtorus fractals.                           +
  8.  
  9. //+ (when you think it's all over... a new one is produced!)         +
  10.  
  11. //+                                                                  +
  12.  
  13. //+ By Ramiro Perez (Panama), RPEREZ@UTPVM1.BITNET                   +
  14.  
  15. //+ and Fausto A. A. Barbuto (Brazil), BJ06@C53000.PETROBRAS.ANRJ.BR +
  16.  
  17. //+ April 9, 1994.                                                   +
  18.  
  19. //+                                                                  +
  20.  
  21. //+ Press any key to stop execution or PAUSE to freeze.              +
  22.  
  23. //+ SVGA256 version; supports up to five video screens.              +
  24.  
  25. //+ Authorized version for spanky.triumf.ca site.                    +
  26.  
  27. //+------------------------------------------------------------------+
  28.  
  29. //
  30.  
  31. #include <time.h>
  32.  
  33. #include <graphics.h>
  34.  
  35. #include <math.h>
  36.  
  37. #include <conio.h>
  38.  
  39. #include <stdlib.h>
  40.  
  41. #include <stdio.h>
  42.  
  43. #include "Svga256.h"
  44.  
  45.  
  46.  
  47. int Vid;  //Global variable
  48.  
  49.  
  50.  
  51. int huge DetectSVGA256()
  52.  
  53. {
  54.  
  55.   printf("\nWhich video mode would you like to use? \n\n");
  56.  
  57.   printf(" 0 - 320x200x256\n");
  58.  
  59.   printf(" 1 - 640x400x256\n");
  60.  
  61.   printf(" 2 - 640x480x256\n");
  62.  
  63.   printf(" 3 - 800x600x256\n");
  64.  
  65.   printf(" 4 - 1024x768x256\n\n>");
  66.  
  67.   scanf("%d",&Vid);
  68.  
  69.   if((Vid<0) || (Vid)>4) Vid = 2;
  70.  
  71.   return Vid;
  72.  
  73. }
  74.  
  75.  
  76.  
  77. void main(void)
  78.  
  79. {
  80.  
  81.   int a, c, nx, ny;
  82.  
  83.   time_t t;
  84.  
  85.   unsigned long k;
  86.  
  87.   double an, can, san, can1, san1, e, r, ax, ay;
  88.  
  89.   double x, xa, x1, x2, x3, y, y1, y2, y3, rand1, rand2;
  90.  
  91.   int graphdriver=DETECT, graphmode;
  92.  
  93.  
  94.  
  95.   clrscr();
  96.  
  97.   printf("\n          Program KAMTORUS.CPP \n\n");
  98.  
  99.   installuserdriver("Svga256",DetectSVGA256);
  100.  
  101.   initgraph(&graphdriver,&graphmode,"C:\\BORLANDC\\BGI");
  102.  
  103.  
  104.  
  105.   if (Vid == 0) { nx = 160; ny = 100; ax =  200.; ay = ax;}
  106.  
  107.   if (Vid == 1) { nx = 320; ny = 200; ax =  300.; ay = ax;}
  108.  
  109.   if (Vid == 2) { nx = 320; ny = 240; ax =  400.; ay = ax;}
  110.  
  111.   if (Vid == 3) { nx = 400; ny = 300; ax =  750.; ay = ax;}
  112.  
  113.   if (Vid == 4) { nx = 512; ny = 359; ax = 1000.; ay = ax;}
  114.  
  115.   if ((Vid>4) || (Vid<0)) { nx = 320; ny = 240; ax = 400; ay = ax;}
  116.  
  117.  
  118.  
  119.   do {
  120.  
  121.     cleardevice();
  122.  
  123.     c = 1;
  124.  
  125.     srand((unsigned) time(&t));
  126.  
  127.     rand1 = random(20000);
  128.  
  129.     rand2 = random(20000);
  130.  
  131.     rand1 = 5.0e-5*rand1;
  132.  
  133.     rand2 = 5.0e-5*rand2;
  134.  
  135.     an = 10.0*(rand1-rand2);
  136.  
  137.     can = 0.99*cos(an);
  138.  
  139.     san = 0.99*sin(an);
  140.  
  141.     can1 = 1.01*cos(an);
  142.  
  143.     san1 = 1.01*sin(an);
  144.  
  145.     for (a=1;a<=256;a++) setpalette (a,(int)(0.0128*random(20000)));
  146.  
  147.     x3 = 0.01;
  148.  
  149.     y3 = 0.01;
  150.  
  151.     do {
  152.  
  153.       xa = x3*x3 - y3;
  154.  
  155.       x2 = x3*can1 + xa*san1;
  156.  
  157.       y2 = x3*san1 - xa*can1;
  158.  
  159.       x3 = x2;
  160.  
  161.       y3 = y2;
  162.  
  163.       x = x2;
  164.  
  165.       y = y2;
  166.  
  167.       a = 0;
  168.  
  169.       do {
  170.  
  171.     xa = x*x - y;
  172.  
  173.     x1 = x*can + xa*san;
  174.  
  175.     y1 = x*san - xa*can;
  176.  
  177.     x  = x1;
  178.  
  179.     y  = y1;
  180.  
  181.     a++;
  182.  
  183.     putpixel((int)(ax*x+nx),(int)(ay*y+ny),c);
  184.  
  185.       }  while ((fabs(x1)<=2.0e3) && (fabs(y1)<=2.0e3) && a<=100);
  186.  
  187.       e = e + 0.075;
  188.  
  189.       c = (int)e % 5 + 1;
  190.  
  191.     } while ((fabs(x2) <= 2.0e3) && (fabs(y2) <= 2.0e3));
  192.  
  193. //*
  194.  
  195. //  Change "k" to increase/decrease time delay between each plot.
  196.  
  197. //  In a DX2-66 k(max)=5000000 produces a time delay of 2-3 seconds.
  198.  
  199. //*
  200.  
  201.     for (k=0;k<=5000000;k++);
  202.  
  203.   } while (!kbhit());
  204.  
  205.   closegraph();
  206.  
  207. }
  208.  
  209.