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

  1. Path: unixg.ubc.ca!news.mic.ucla.edu!library.ucla.edu!europa.eng.gtefsd.com!paladin.american.edu!auvm!NS.PA!rperez
  2.  
  3. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  4.  
  5. Newsgroups: bit.listserv.frac-l
  6.  
  7. Mime-Version: 1.0
  8.  
  9. Content-Type: TEXT/PLAIN; charset=US-ASCII
  10.  
  11. content-length: 19571
  12.  
  13. Message-ID: <Pine.3.89.9412230132.A11881-0100000@ns.pa>
  14.  
  15. Date: Fri, 23 Dec 1994 01:14:00 -0500
  16.  
  17. Sender: "\"FRACTAL\" discussion list" <FRAC-L@GITVM1.BITNET>
  18.  
  19. From: Ramiro Perez <rperez@NS.PA>
  20.  
  21. Subject: A fractal gift for frac-l people (warning:long)
  22.  
  23. Lines: 738
  24.  
  25.  
  26.  
  27. Hello,
  28.  
  29.  
  30.  
  31. Firstly, Merry Christmas to all,
  32.  
  33.  
  34.  
  35. Here's a program that I've made, which displays 40 strange attractors in SVGA.
  36.  
  37. This program has the ability to search for strange attractors testing the
  38.  
  39. equations with random parameters until an attractor is found.
  40.  
  41.  
  42.  
  43. I offer this program as a Christmas gift to FRAC-L people, but since I got
  44.  
  45. a pulmonary sickness during the last week, I didn't build the full
  46.  
  47. documentation. Anyways, the program is completed, and I will build a full
  48.  
  49. doc as soon as I feel better -  but don't worry, here is a small explanation
  50.  
  51. on how to use the program, so enjoy it!
  52.  
  53.  
  54.  
  55. First, the program asks you the video mode you're willing to use, then what
  56.  
  57. attractor do you want to test.
  58.  
  59.  
  60.  
  61. Once you select the video mode and the attractor type the program asks you
  62.  
  63. about the type of the colouring method you want. There are two options: by
  64.  
  65. Distance, on where the program uses a rainbow palette and the colour is
  66.  
  67. determined by the distance between the last iteration and the actual
  68.  
  69. iteration (use this with the 32,36,20 and any other you may will), and by
  70.  
  71. Frequency, on where the program use a blue palette. This one is an old
  72.  
  73. method for displaying attractors, on where the colour of the pixel is
  74.  
  75. determined by the number of times the orbit is visited by it.
  76.  
  77.  
  78.  
  79. After that, the program asks you if you wish to change the colours. At this
  80.  
  81. point you can load a fractint map file if you wish, or use the default colour
  82.  
  83. maps that are included on the program (a rainbow palette that I got from
  84.  
  85. frac-xtra, and a blue-grey palette which is internally calculated).
  86.  
  87.  
  88.  
  89. Then the fun begins:  first, the program assigns a random value to the
  90.  
  91. parameters (p1,p2..p16) of the equation, then the iteration cycle begins.
  92.  
  93. The parameters are changed if the iteration goes to the infinity or fall into
  94.  
  95. a periodic cycle, and the line at the top of the screen is increased by one
  96.  
  97. pixel.
  98.  
  99.  
  100.  
  101. If the iteration counter reach to 10000, the program computes the
  102.  
  103. corners of the attractor, clears the screen, and the image begins
  104.  
  105. to materialize on the screen.
  106.  
  107.  
  108.  
  109. If you choose the default blue palette for the display method, you shall
  110.  
  111. wait for the image (turn off the light if you have selected a very dark
  112.  
  113. p8alette which has very dark first colours)..
  114.  
  115.  
  116.  
  117. In some cases, the attractor is an invariant circle, then press the space bar
  118.  
  119. to skip it.  (you can press the spc bar if you don't like the image that you
  120.  
  121. are seeing, at any time of the entire process)
  122.  
  123.  
  124.  
  125. The flashes that you see in the screen are due to the orbits, on where I've
  126.  
  127. changed the first colours to white in order to see the form of them. (the
  128.  
  129. palette returns to the normal when the attractor is choosen)
  130.  
  131.  
  132.  
  133. Well, as an example, try Storm Julia with the Frequency display metod, and a
  134.  
  135. brightness value of 1 for the default colours (turn off the lights), or
  136.  
  137. ifs/ikeda in the same form (in this case, press the spc bar until you see
  138.  
  139. something interesting). For the distance colouring method use the star,
  140.  
  141. icons, and frothystars, and wait until the image is complete.
  142.  
  143.  
  144.  
  145. I got the inspiration thanks to the images that The Flame program
  146.  
  147. (created by Scott Draves) which also apears on the book written by
  148.  
  149. Mr. Julien Sproot which is related to the search of Strange attractors,
  150.  
  151. But since I don't have the book  I don't know how it works.
  152.  
  153.  
  154.  
  155.              Sincerely
  156.  
  157.  
  158.  
  159.                        Ramiro Perez
  160.  
  161.  
  162.  
  163.  
  164.  
  165. PS: I've made all of the attractors in this program, except the ones marked
  166.  
  167. with asteriscs, such as the one called King's Dreams, that was made by Dr.
  168.  
  169. Clifford A. Pickover.
  170.  
  171.  
  172.  
  173. //+-----------------------------------------------------+
  174.  
  175. //|Program SVGATTR.CPP by Ramiro Perez (rperez@ns.pa)   |
  176.  
  177. //|Displays 40 Strange Attractors in SVGA video modes   |
  178.  
  179. //|Requires the svga256.bgi driver made by Jordan Powell|
  180.  
  181. //|Hargrave.                                            |
  182.  
  183. //|Random number generator by Michael Sargent           |
  184.  
  185. //+-----------------------------------------------------+
  186.  
  187.  
  188.  
  189.  
  190.  
  191. #include <math.h>
  192.  
  193. #include <graphics.h>
  194.  
  195. #include <conio.h>
  196.  
  197. #include <stdlib.h>
  198.  
  199. #include <stdio.h>
  200.  
  201. float p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,x1,y1,pi;
  202.  
  203. int Video;
  204.  
  205. int sw2;
  206.  
  207. int cr[257],cg[257],cb[257],i,br;
  208.  
  209. char ranr[256]={12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,
  210.  
  211. 13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,32,33,34,35,36,37,40,
  212.  
  213. 39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,63,63,
  214.  
  215. 63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,
  216.  
  217. 63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,
  218.  
  219. 63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,62,61,60,59,58,57,56,55,54,
  220.  
  221. 53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,
  222.  
  223. 28,27,26,25,24,23,22,21,20,19,18,17,16,16,16,15,15,15,14,14,14,13,13,13,12,
  224.  
  225. 12,12,11,11,11,10,10,10,9,9,9,8,8,7,7,7,6,6,6,5,5,5,4,4,4,3,3,3,2,2,2,1,1,
  226.  
  227. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  228.  
  229.  
  230.  
  231. char rang[256]={12,18,16,15,14,12,11,10,8,7,6,4,3,2,0,0,0,0,0,0,0,0,0,0,0,
  232.  
  233. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  234.  
  235. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,
  236.  
  237. 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,
  238.  
  239. 43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,63,63,63,63,
  240.  
  241. 63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,
  242.  
  243. 63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,62,62,62,61,
  244.  
  245. 61,60,60,60,59,59,58,58,58,57,57,56,56,56,55,55,54,54,54,53,53,53,52,52,51,
  246.  
  247. 51,51,50,50,49,49,49,48,48,47,47,47,46,46,45,44,43,42,40,39,38,36,35,34,32,
  248.  
  249. 31,30,28,27,26,24,23,22,20,19};
  250.  
  251.  
  252.  
  253. char ranb[256]={12,52,53,53,54,55,56,57,58,58,59,60,61,62,63,62,61,60,59,58,
  254.  
  255. 57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,
  256.  
  257. 31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,
  258.  
  259. 5,4,3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  260.  
  261. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  262.  
  263. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  264.  
  265. 0,0,0,0,0,0,0,0,0,1,2,3,3,4,5,6,6,7,8,9,9,10,11,12,12,13,14,15,15,16,17,18,
  266.  
  267. 19,19,20,21,22,22,23,24,25,25,26,27,28,28,29,30,31,31,32,33,34,35,35,36,37,
  268.  
  269. 38,39,39,40,41,42,43,44,44,45,46,47,48,48,49,50,51};
  270.  
  271.  
  272.  
  273. int huge DetectSVGA256()
  274.  
  275. {
  276.  
  277.   if ((Video>4) || (Video<0)) Video = 2;
  278.  
  279.   return Video;
  280.  
  281. }
  282.  
  283. double rnd(void);
  284.  
  285.         void cmaps(int p);
  286.  
  287.  
  288.  
  289. /*Routine for computing the corners*/
  290.  
  291. void rwindow(float xm, float ym, float xa, float ya, float *dx, float *dy,
  292.  
  293.                 float *lx, float *ly)
  294.  
  295. {
  296.  
  297.   float diax,diay;
  298.  
  299.   diax=(xa-xm);
  300.  
  301.   diay=(ym-ya);
  302.  
  303.   *dx=getmaxx()/diax;
  304.  
  305.   *dy=getmaxy()/diay;
  306.  
  307.   *lx=xm * *dx;
  308.  
  309.   *ly=ya * *dy;
  310.  
  311. }
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319. void fmap(void) { /*routine for reading a Fractint map file*/
  320.  
  321.  
  322.  
  323.    FILE *fp;
  324.  
  325.    char ch[100];
  326.  
  327.    i=0;
  328.  
  329.    system("Dir *.map /w /p");
  330.  
  331.    printf("\nMap File: ");
  332.  
  333.    scanf("%s",&ch);
  334.  
  335.    if ((fp=fopen(ch,"rt"))==NULL){
  336.  
  337.     printf("cannot open map file \n");
  338.  
  339.     }
  340.  
  341.     else {
  342.  
  343.    do
  344.  
  345.    {
  346.  
  347.    if (fscanf(fp, "%i%i%i", &cr[i],&cg[i],&cb[i])!=3) fgets(ch,80,fp);
  348.  
  349.    else {
  350.  
  351.    cr[i]=(int)(cr[i]/4);
  352.  
  353.    cb[i]=(int)(cb[i]/4);
  354.  
  355.    cg[i]=(int)(cg[i]/4);
  356.  
  357.    i++;
  358.  
  359.     }
  360.  
  361.     } while(!feof(fp));
  362.  
  363.  
  364.  
  365.    fclose(fp);
  366.  
  367.    printf("Done \n");
  368.  
  369.    }
  370.  
  371.    }
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  void cmap(void){ /* blue palette for frecuency plots*/
  378.  
  379.  printf("\nBrightness 0--10 (0=darkest, 10=brightness):");
  380.  
  381.  scanf("%d",&br);
  382.  
  383.  for (i=1; i<=255; i++){
  384.  
  385.     cr[i]=i*0.25+br; if (cr[i]>63) cr[i]=63;
  386.  
  387.     cg[i]=i*0.25+br; if (cg[i]>63) cg[i]=63;
  388.  
  389.     cb[i]=5+i*.2+br; if (cb[i]>63) cb[i]=63;
  390.  
  391.     }
  392.  
  393.  }
  394.  
  395.  
  396.  
  397.  void rmap(void){ /*rainbow palette for distance plot*/
  398.  
  399.   for (i=1; i<=255; i++){
  400.  
  401.     cr[i]=ranr[i];
  402.  
  403.     cg[i]=rang[i];
  404.  
  405.     cb[i]=ranb[i];
  406.  
  407.     }
  408.  
  409.     }
  410.  
  411.  
  412.  
  413. void selectv()
  414.  
  415. {
  416.  
  417.  clrscr();
  418.  
  419.  printf("\n Which video mode would you like to use? \n\n");
  420.  
  421.  printf(" 0 - 320x200x256\n");
  422.  
  423.  printf(" 1 - 640x400x256\n");
  424.  
  425.  printf(" 2 - 640x480x256 (suggested when available)\n");
  426.  
  427.  printf(" 3 - 800x600x256\n");
  428.  
  429.  printf(" 4 - 1024x768x256\n\n> ");
  430.  
  431.  scanf("%d",&Video);
  432.  
  433.   if ((Video>4) || (Video<0)) Video = 2;
  434.  
  435. }
  436.  
  437.  
  438.  
  439. void main() { /*Main!*/
  440.  
  441.     int k,a,b,op,j,l,col;
  442.  
  443.     float z,dx,dy,lx,ly,x,y,rad;
  444.  
  445.     float xb,yb,s,c1;
  446.  
  447.     float xn1,yn1,xa,ya;
  448.  
  449.     float xm,ym,xc,yc,ax,ay;
  450.  
  451.     float tx,ty,tx1,ty1,tx2,ty2,tx3,ty3,tz,xr,yr;
  452.  
  453.     int x2,y2,p;
  454.  
  455.     char sw,ch;
  456.  
  457.     int graphdriver=DETECT, graphmode;
  458.  
  459.     sw2=0;
  460.  
  461.     sw=5;
  462.  
  463.     pi=3.141592653;
  464.  
  465.     selectv();
  466.  
  467.     installuserdriver("Svga256",DetectSVGA256);
  468.  
  469.     for (i=1; i<=255; i++){
  470.  
  471.     cr[i]=i*0.25+br; if (cr[i]>63) cr[i]=63;
  472.  
  473.     cg[i]=i*0.25+br; if (cg[i]>63) cg[i]=63;
  474.  
  475.     cb[i]=5+i*.2+br; if (cb[i]>63) cb[i]=63;
  476.  
  477.     }
  478.  
  479.  
  480.  
  481.  
  482.  
  483. do {
  484.  
  485. clrscr();
  486.  
  487. printf("Phase Space I: 2D Strange Attractors  \n");
  488.  
  489. printf("by Ramiro Perez (rperez@ns.pa)\n");
  490.  
  491. printf("Select :\n");
  492.  
  493. printf("           1 -Atoms                           21 -Conditional Ifs\n");
  494.  
  495. printf("           2 -Double Helix                    22 -Storm Julia(imm/imm)\n
  496.  
  497. ");
  498.  
  499. printf("           3 -Mult. Param. 1                  23*-Duffing Oscillator\n")
  500.  
  501. ;
  502.  
  503. printf("           4 -Mult. Param. 2                  24*-GingerBreadman\n");
  504.  
  505. printf("           5 -Thing                           25*-King's Dream\n");
  506.  
  507. printf("           6 -Ginger-Hop                      26*-Samardiza Oscillator\n
  508.  
  509. ");
  510.  
  511. printf("           7 -Loops                           27*-Ikeda\n");
  512.  
  513. printf("           8 -Rings                           28*-FrothyBasin formula\n"
  514.  
  515. );
  516.  
  517. printf("           9 -X wings                         29 -Cosine\n");
  518.  
  519. printf("          10 -Ameba                           30 -Frost Julia\n");
  520.  
  521. printf("          11 -Mult. Param. 3                  31 -FrothyStars\n");
  522.  
  523. printf("          12 -Ifs-Mandel                      32 -Star (icon 4 var.)\n")
  524.  
  525. ;
  526.  
  527. printf("          13*-Ifs                             33 -Spirals (kamtorus var.
  528.  
  529. )\n");
  530.  
  531. printf("          14 -Iris                            34 -Ifs/Icon4\n");
  532.  
  533. printf("          15 -Medusa                          35 -Flakes in the Wind\n")
  534.  
  535. ;
  536.  
  537. printf("          16 -Mult. Param. 4                  36*-Icons\n");
  538.  
  539. printf("          17 -Disk                            37*-Duffing II\n");
  540.  
  541. printf("          18 -Strips                          38*-Volterra\n");
  542.  
  543. printf("          19 -Real Mandelbrot                 39 -Paintings\n");
  544.  
  545. printf("          20 -Ikeda/Ifs                       40 -Cosine Waves\n");
  546.  
  547. printf("                           Option:");
  548.  
  549. scanf("%d",&op);
  550.  
  551. clrscr();
  552.  
  553. printf ("Colouring metod:  [D]istance or  [F]recuency:");
  554.  
  555. ch=getch();
  556.  
  557. if (ch=='D' || ch=='d') sw2=1; else sw2=0;
  558.  
  559. if ((ch=='D' || ch=='d') && sw==5) rmap();
  560.  
  561. printf ("\nDo you wish to Change the Colours (Y/N):");
  562.  
  563.         ch=getch();
  564.  
  565.         if (ch =='y' || ch=='Y') {
  566.  
  567.         printf ("\nDo you wish to load a fractint map file (Y/N):");
  568.  
  569.         ch=getch();
  570.  
  571.         if (ch =='y' || ch=='Y') fmap(); else {
  572.  
  573.         printf ("\nDo you wish to use the default colour map (Y/N):");
  574.  
  575.         ch=getch();
  576.  
  577.         if (ch =='y' || ch=='Y')
  578.  
  579.         {
  580.  
  581.          if (sw2==1) rmap(); else cmap();
  582.  
  583.          }
  584.  
  585.         }
  586.  
  587.         }
  588.  
  589.  
  590.  
  591.     initgraph(&graphdriver,&graphmode,"C:\\BORLANDC\\BGI");
  592.  
  593.     cleardevice();
  594.  
  595.     for (i=1; i<=255; i++){
  596.  
  597.     setrgbpalette(i, cr[i], cg[i], cb[i]);
  598.  
  599.     putpixel(i,0,i);
  600.  
  601.     }
  602.  
  603.     kbhit();
  604.  
  605.     randomize();
  606.  
  607.     rwindow (-2,-1.5,2,1.5,&dx,&dy,&lx,&ly);
  608.  
  609.     l=0;
  610.  
  611.  
  612.  
  613.     do { /*Initializing the variables and palettes*/
  614.  
  615.           rad=1;
  616.  
  617.           cleardevice();
  618.  
  619.           x=(rnd()-rnd())*0.25;
  620.  
  621.           y=(rnd()-rnd())*0.25;
  622.  
  623.           sw=0; j=random(10);
  624.  
  625.           p1=(rnd()-rnd())*2; p2=(rnd()-rnd())*2;
  626.  
  627.           p3=(rnd()-rnd())*2; p4=(rnd()-rnd())*2;
  628.  
  629.           p5=(rnd()-rnd())*2; p6=(rnd()-rnd())*2;
  630.  
  631.           p7=(rnd()-rnd())*2; p8=(rnd()-rnd())*2;
  632.  
  633.           p9=(rnd()-rnd())*2; p10=(rnd()-rnd())*2;
  634.  
  635.           p11=(rnd()-rnd())*2; p12=(rnd()-rnd())*2;
  636.  
  637.           p13=(rnd()-rnd())*2; p14=(rnd()-rnd())*2;
  638.  
  639.           p15=(rnd()-rnd())*2; p16=(rnd()-rnd())*2;
  640.  
  641.           tx=1; ty=1; tz=1;
  642.  
  643.           xa=0; ya=0; xc=0; yc=0; xm=0; ym=0; k=0; l++;
  644.  
  645.           rwindow (-2,-1.5,2,1.5,&dx,&dy,&lx,&ly);
  646.  
  647.           setcolor(getmaxcolor());
  648.  
  649.           if (l>getmaxx()) l=0;
  650.  
  651.           line (0,0,l,0);
  652.  
  653.           setrgbpalette(1,63,63,63);
  654.  
  655.           setrgbpalette(2,63,63,63);
  656.  
  657.           setrgbpalette(3,63,63,63);
  658.  
  659.           setrgbpalette(4,63,63,63);
  660.  
  661.           setrgbpalette(255,63,63,63);
  662.  
  663.  
  664.  
  665. do
  666.  
  667. {
  668.  
  669. switch (op) {
  670.  
  671.  
  672.  
  673. case 1:{ /* Atoms */
  674.  
  675.         x1=x*sin(y)+cos(y)*4*p1;
  676.  
  677.         y1=y*cos(x)+sin(y)*4*p1;
  678.  
  679.         }; break;
  680.  
  681.  
  682.  
  683. case 2:{ /* Double Helix */
  684.  
  685.         x1=x+(y*p1)*2;
  686.  
  687.         y1=(p1*x-p2*y)*(p2+x*x);
  688.  
  689.         };break;
  690.  
  691.  
  692.  
  693. case 3:{ /* Mult. Param. 1 */
  694.  
  695.         x1=x*(p2*y+p3*x+p4)+y*(p5*x+y)+p1;
  696.  
  697.         y1=x*(p8*y+p9*x+p10)+y*(p11*x+y)+p7;
  698.  
  699.         }; break;
  700.  
  701.  
  702.  
  703. case 4:{ /* Mult. Param. 2 */
  704.  
  705.         x1=p1*x+x*(p2*y+p3*x*x)+p4*y+y*(p5*x+p6*y*y);
  706.  
  707.         y1=p7*x+x*(p8*y+p9*x*x)+p10*y+y*(p11*x+p12*y*y);
  708.  
  709.         }; break;
  710.  
  711.  
  712.  
  713. case 5:{ /* Thing */
  714.  
  715.         x1=-x*y+p2+x*(1-y);
  716.  
  717.         y1=x*x-p1*y;
  718.  
  719.         }; break;
  720.  
  721.  
  722.  
  723. case 6:{ /* Ginger-Hop */
  724.  
  725.         x1=y-p2*sqrt(fabs(x*p1));
  726.  
  727.         y1=-x;
  728.  
  729.         }; break;
  730.  
  731.  
  732.  
  733. case 7:{ /* Loops */
  734.  
  735.         p3=p1*x-p2*y;
  736.  
  737.         x1=p3*(-p1+y*y);
  738.  
  739.         y1=p3*(x*x+p2);
  740.  
  741.         }; break;
  742.  
  743.  
  744.  
  745. case 8:{ /* Rings */
  746.  
  747.         p3=x*x*x;
  748.  
  749.         x1=(4*p3+y*y*y-2*x)/p1;
  750.  
  751.         y1=(p3*x+3*y*y-x*x)/p2;
  752.  
  753.         }; break;
  754.  
  755.  
  756.  
  757. case 9:{ /* Wings */
  758.  
  759.         if (x>0) p1=1; else p1=-1;
  760.  
  761.         x1=x-p1*sqrt(fabs(y-p3*x));
  762.  
  763.         y1=x*p2+y;
  764.  
  765.         }; break;
  766.  
  767.  
  768.  
  769. case 10:{ /* Ameba */
  770.  
  771.         x1=-p1*x+p1*y;
  772.  
  773.         y1=p2*x-y*y*x;
  774.  
  775.         }; break;
  776.  
  777.  
  778.  
  779. case 11:{ /* Mult. Param. 3 */
  780.  
  781.         x1= (p1+(x*x-p2)+x*(x-p4*y))+y*(y*y-p6);
  782.  
  783.         y1= (p7+(x*x-p8)+x*(x-p9*y))+y*(y*y-p10);
  784.  
  785.         }; break;
  786.  
  787.  
  788.  
  789. case 12:{ /* Ifs-Mandel */
  790.  
  791.         x1 = p1*x+p2*y+p3+(x*x-y*y+p7);
  792.  
  793.         y1 = p4*x+p5*y+p6+(2*x*y+p8);
  794.  
  795.         }; break;
  796.  
  797.  
  798.  
  799. case 13:{ /* Ifs */
  800.  
  801.         if (rnd()>0.5){
  802.  
  803.         x1=p1*x*0.5+p2*y*0.5+p5;
  804.  
  805.         y1=-p2*x*0.5+p1*y*0.5+p6;
  806.  
  807.         }
  808.  
  809.         else
  810.  
  811.         {
  812.  
  813.         x1=p3*x*0.5+p4*y*0.5+p7;
  814.  
  815.         y1=-p4*x*0.5+p3*y*0.5+p8;
  816.  
  817.         }
  818.  
  819.         }; break;
  820.  
  821.  
  822.  
  823. case 14:{ /* Iris */
  824.  
  825.         x1=sin(x)*p1+cos(y)*p2;
  826.  
  827.         y1=cos(x)*p1+sin(y)*p2;
  828.  
  829.         }; break;
  830.  
  831.  
  832.  
  833. case 15:{ /* Medusa */
  834.  
  835.         x1=p1*x+y-p2*x*x;
  836.  
  837.         y1=p3*y-x+p2*y*y;
  838.  
  839.         }; break;
  840.  
  841.  
  842.  
  843. case 16:{ /* Mult. Param. 4 */
  844.  
  845.         x1=p1*x+y*(p9+p2*x-y*p3+p4*y*y);
  846.  
  847.         y1=p5*x+y*(p10+p6*x-y*p7+p8*y*y);
  848.  
  849.         }; break;
  850.  
  851.  
  852.  
  853. case 17:{ /* Disk */
  854.  
  855.         x1=p1+p2*(x*cos(x*y)-y*sin(x*y));
  856.  
  857.         y1=p2*(x*sin(x*y)+y*cos(x*y));
  858.  
  859.         }; break;
  860.  
  861.  
  862.  
  863. case 18:{ /* Strips */
  864.  
  865.         x1=sin(y/x)*p1+cos(y)*p2;
  866.  
  867.         y1=cos(y/x)*p3+sin(x)*p4;
  868.  
  869.         }; break;
  870.  
  871.  
  872.  
  873. case 19:{ /* Real Mandelbrot */
  874.  
  875.         y1=x*x-p1;
  876.  
  877.         x1=y;
  878.  
  879.         }; break;
  880.  
  881.  
  882.  
  883. case 20:{ /* Ikeda/Ifs */
  884.  
  885.         if (rnd()>0.7){
  886.  
  887.         p4=p1-6/(1+x*x+y*y);
  888.  
  889.         x1=1+p2*(x*cos(p4)-y*sin(p4));
  890.  
  891.         y1=p2*(x*sin(p4)+y*cos(p4));
  892.  
  893.         }
  894.  
  895.         else
  896.  
  897.         {
  898.  
  899.         x1=p10*x+p9*y+p11;
  900.  
  901.         y1=-p9*x+p10*y+p12;
  902.  
  903.         }
  904.  
  905.         }; break;
  906.  
  907.  
  908.  
  909. case 21:{ /* Conditional Ifs */
  910.  
  911.         if (x>0){
  912.  
  913.         x=x-1;
  914.  
  915.         x1=p1*x-p2*y+p3;
  916.  
  917.         y1=p1*y+p2*x+p4;
  918.  
  919.         }
  920.  
  921.         else {
  922.  
  923.         x=x+1;
  924.  
  925.         x1=p1*x+p2*y-p3;
  926.  
  927.         y1=p1*y-p2*x-p4;
  928.  
  929.         }
  930.  
  931.         }; break;
  932.  
  933.  
  934.  
  935. case 22:{ /* Storm Julia */
  936.  
  937.         if (rnd()>rnd()){ x=x-p1; y=y-p2; }
  938.  
  939.         else
  940.  
  941.         { x=x-p4; y=y-p5; }
  942.  
  943.         p3=sqrt(x*x+y*y);
  944.  
  945.         x1=sqrt((x + p3)/2);
  946.  
  947.         y1=sqrt((-x + p3)/2);
  948.  
  949.         if (y<0) y1=-y1;
  950.  
  951.         if (rnd()>rnd()){
  952.  
  953.         x1=-x1;
  954.  
  955.         y1=-y1;
  956.  
  957.         }
  958.  
  959.         }; break;
  960.  
  961.  
  962.  
  963. case 23:{ /* Duffing Oscillator */
  964.  
  965.         p1++;
  966.  
  967.         if (p1>627) p1=0;
  968.  
  969.         p2=0.01*p1;
  970.  
  971.         x1 = x + y/6.283184;
  972.  
  973.         y1 = y + (-(x*x*x) + x-p3*y + p4*cos(p2))/6.283184;
  974.  
  975.         }; break;
  976.  
  977.  
  978.  
  979. case 24:{ /* Gingerbreadman */
  980.  
  981.         x1=p1-y+fabs(x);
  982.  
  983.         y1=x;
  984.  
  985.         }; break;
  986.  
  987.  
  988.  
  989. case 25:{ /* King's Dream */
  990.  
  991.         x1=sin(y*p2)+p3*sin(x*p2);
  992.  
  993.         y1=sin(x*p1)+p4*sin(y*p1);
  994.  
  995.         }; break;
  996.  
  997.  
  998.  
  999. case 26:{ /* Samardiza Oscillator */
  1000.  
  1001.         x1=x+(p1*x+p2*y-p7)*0.05;
  1002.  
  1003.         y1=y+(x+p5*y-x*x*x)*0.05;
  1004.  
  1005.         p7=p7+x*p6*0.01;
  1006.  
  1007.         }; break;
  1008.  
  1009.  
  1010.  
  1011. case 27:{ /* Ikeda */
  1012.  
  1013.         p4=p1-6/(1+x*x+y*y);
  1014.  
  1015.         x1=1+p2*(x*cos(p4)-y*sin(p4));
  1016.  
  1017.         y1=p2*(x*sin(p4)+y*cos(p4));
  1018.  
  1019.         }; break;
  1020.  
  1021.  
  1022.  
  1023. case 28:{ /* FrothyBasin Formula */
  1024.  
  1025.         x1=x*x-y*y-p1*x-p2*-y;
  1026.  
  1027.         y1=2*x*y-p1*-y+p2*x;
  1028.  
  1029.         }; break;
  1030.  
  1031.  
  1032.  
  1033. case 29:{ /* Cosine */
  1034.  
  1035.         x1 = cos(x+x*(p2*y+p3*x+p4)+p2*y*(x*x-p5)+p12)+p8*x;
  1036.  
  1037.         y1 = cos(y+x*(p6*y+p9*x+p10)+p1*y*(x*x+p11)+p7)+p13*y;
  1038.  
  1039.         }; break;
  1040.  
  1041.  
  1042.  
  1043. case 30:{ /* Frost Julia */
  1044.  
  1045.         p1=x-p11; p2=y-p12;
  1046.  
  1047.         if (p1>0) p3= atan(p2/p1);
  1048.  
  1049.         if (p1 < 0) p3=3.141592+atan(p2/p1);
  1050.  
  1051.         if (p1 == 0) p3=0.5*3.141592653;
  1052.  
  1053.         p3 = 0.5*p3;
  1054.  
  1055.         p4 = p1*p1 + p2*p2;
  1056.  
  1057.         p4 = sqrt(sqrt(sqrt(p4*p4*p4)));
  1058.  
  1059.         if (rnd()>rnd()) p4=-p4;
  1060.  
  1061.         x1 = p4*cos(p3);
  1062.  
  1063.         y1 = p4*sin(p3);
  1064.  
  1065.         }; break;
  1066.  
  1067.  
  1068.  
  1069. case 31:{ /* FrothyStars */
  1070.  
  1071.         p2=x;
  1072.  
  1073.         p3=y;
  1074.  
  1075.         for (i=1;i<=j;i++){
  1076.  
  1077.         p4=p2*x-p3*y;
  1078.  
  1079.         p3=p3*x+p2*y;
  1080.  
  1081.         p2=p4;
  1082.  
  1083.         }
  1084.  
  1085.         x1=p2-p5*x-p6*-y;
  1086.  
  1087.         y1=p3-p5*-y+p6*x;
  1088.  
  1089.         }; break;
  1090.  
  1091.  
  1092.  
  1093. case 32:{ /* Star */
  1094.  
  1095.         p4=sqrt(x*x);
  1096.  
  1097.         p5=sqrt(y*y);
  1098.  
  1099.         x1=p1*4*x+p2*4*x*(p4+p5)+p3*4*(x*p4-x*p5);
  1100.  
  1101.         y1=p1*4*y+p2*4*y*(p4+p5)+p3*4*(-p4*y+y*p5);
  1102.  
  1103.         }; break;
  1104.  
  1105.  
  1106.  
  1107. case 33:{ /* Spirals */
  1108.  
  1109.         if (k==0) {
  1110.  
  1111.         p10=1+rnd()*0.05; p3=sin(p5*6.28)*p10; p4=cos(p5*6.28)*p10; }
  1112.  
  1113.         p9=x*x-y;
  1114.  
  1115.         p1=x*p3+p9*p4;
  1116.  
  1117.         p2=x*p4-p9*p3;
  1118.  
  1119.         p7=sqrt(p1*p1+p2*p2);
  1120.  
  1121.         if (p7>2) { p1=-p1*0.005; p2=-p2*0.005; }
  1122.  
  1123.         x1=p1;
  1124.  
  1125.         y1=p2;
  1126.  
  1127.         }; break;
  1128.  
  1129.  
  1130.  
  1131. case 34:{ /* Ifs/Icon4 */
  1132.  
  1133.         if (rnd()>.75){
  1134.  
  1135.         p4=x*x;
  1136.  
  1137.         p5=y*y;
  1138.  
  1139.         x1=p1*4*x+p2*4*x*(p4+p5);
  1140.  
  1141.         y1=p1*4*y+p2*4*y*(p4+p5);
  1142.  
  1143.         }
  1144.  
  1145.         else {
  1146.  
  1147.         x1=p7*x+p8*y+p9;
  1148.  
  1149.         y1=-p8*x+p7*y+p10;
  1150.  
  1151.         }
  1152.  
  1153.         }; break;
  1154.  
  1155.  
  1156.  
  1157. case 35:{ /* Flakes in the Wind */
  1158.  
  1159.         if (rnd()>0.3) {
  1160.  
  1161.         if (rnd()>0.5){
  1162.  
  1163.         x1=0.5*p1*x+0.5*p2*y+p5;
  1164.  
  1165.         y1=-0.5*p2*x+0.5*p1*y+p6;
  1166.  
  1167.         }
  1168.  
  1169.         else
  1170.  
  1171.         {
  1172.  
  1173.         x1=0.5*p3*x+0.5*p4*y+p7;
  1174.  
  1175.         y1=-0.5*p4*x+0.5*p3*y+p8;
  1176.  
  1177.         }
  1178.  
  1179.         } else {
  1180.  
  1181.         p10=random(3);
  1182.  
  1183.         if (p10==0) { p11=-0.5*p11+0.25; p13=-0.5*p12+0.08+0.25; }
  1184.  
  1185.         if (p10==1) { p11=-0.5*p11-0.072+0.25; p13=-0.5*p12-0.048+0.25; }
  1186.  
  1187.         if (p10==2) { p11=-0.5*p11+0.072+0.25; p13=-0.5*p12-0.048+0.25; }
  1188.  
  1189.         p12=p13;
  1190.  
  1191.         x1=p11;
  1192.  
  1193.         y1=p12;
  1194.  
  1195.  
  1196.  
  1197.         }
  1198.  
  1199.         }; break;
  1200.  
  1201.  
  1202.  
  1203. case 36:{ /* Icons */
  1204.  
  1205.         p1=x*x+y*y;
  1206.  
  1207.         p2=x;
  1208.  
  1209.         p3=y;
  1210.  
  1211.         for (i=1;i<=j;i++){
  1212.  
  1213.         p4=p2*x-p3*y;
  1214.  
  1215.         p3=p3*x+p2*y;
  1216.  
  1217.         p2=p4;
  1218.  
  1219.         }
  1220.  
  1221.         p5=x*p2-y*p3;
  1222.  
  1223.         p6=p10*8+p7*8*p1+p8*8*p5;
  1224.  
  1225.         x1=p6*x+p9*8*p2;
  1226.  
  1227.         y1=p6*y-p9*8*p3;
  1228.  
  1229.         }; break;
  1230.  
  1231.  
  1232.  
  1233. case 37:{ /* Duffing II */
  1234.  
  1235.         x1=x+(p1*y)*0.1;
  1236.  
  1237.         y1=y+(p2*x+p3*x*x*x+p5*x*y*y+p6*y+p7*y*y*y+p8*sin(p11))*0.1;
  1238.  
  1239.         p11=p11+(p9+p10*x*y)*0.1;
  1240.  
  1241.         }; break;
  1242.  
  1243.  
  1244.  
  1245. case 38:{ /* Volterra */
  1246.  
  1247.         if (k==0) { x=1.01; y=0.99; p5=fabs(p7)/2; p6=fabs(p8)/2; }
  1248.  
  1249.         p3=x-x*y;
  1250.  
  1251.         p4=-y+x*y;
  1252.  
  1253.         p1=x+p6*p3;
  1254.  
  1255.         p2=y+p6*p4;
  1256.  
  1257.         x1=x+p5*(p3+(p1-p1*p2));
  1258.  
  1259.         y1=y+p5*(p4+(-p2+p1*p2));
  1260.  
  1261.         }; break;
  1262.  
  1263.  
  1264.  
  1265. case 39:{ /* Paintings */
  1266.  
  1267.         p1=fabs(y-p7*sin(x));
  1268.  
  1269.         p1=fabs((int)(p1)-p1);
  1270.  
  1271.         p2=fabs(x*p8);
  1272.  
  1273.         p2=fabs((int)(p2)-p2);
  1274.  
  1275.         p3=x+p9+p11*p1;
  1276.  
  1277.         x1=fabs((int)(p3)-p3);
  1278.  
  1279.         p4=y+p10+p12*p2;
  1280.  
  1281.         y1=fabs((int)(p4)-p4);
  1282.  
  1283.         }; break;
  1284.  
  1285.  
  1286.  
  1287. case 40:{ /* Cosine Waves */
  1288.  
  1289.         x1=y-p1*cos(x*3.1415);
  1290.  
  1291.         y1=x*p2;
  1292.  
  1293.         }; break;
  1294.  
  1295.  
  1296.  
  1297. }
  1298.  
  1299.  
  1300.  
  1301.         if (x1*x1+y1*y1>50) sw=1;
  1302.  
  1303.         if (k<10000){
  1304.  
  1305.           col=1;
  1306.  
  1307.           k++;
  1308.  
  1309.           xn1=fabs(fabs(x1)-fabs(xa));
  1310.  
  1311.           yn1=fabs(fabs(y1)-fabs(ya));
  1312.  
  1313.           if (rnd()>0.7){ xa=x1; ya=y1; }
  1314.  
  1315.  
  1316.  
  1317.           if ((yn1<0.00005) && (xn1<0.00005)) sw=1;
  1318.  
  1319.  
  1320.  
  1321.           if (k<=1000) { xm=x1; ym=y1; xc=x1; yc=y1; }
  1322.  
  1323.           if (k==995) { tx1=x1; ty1=y1; }
  1324.  
  1325.           if (k==997) { tx2=x1; ty2=y1; }
  1326.  
  1327.           if (k==999) { tx3=x1; ty3=y1; }
  1328.  
  1329.           if (k>1000 && k<=10000) { /*Routine for invariant circles*/
  1330.  
  1331. 8               if (x1<xm) xm=x1;
  1332.  
  1333.                 if (y1<ym) ym=y1;
  1334.  
  1335.                 if (x1>xc) xc=x1;
  1336.  
  1337.                 if (y1>yc) yc=y1;
  1338.  
  1339.                 if (tx>0.00025) tx=sqrt(pow(x1-tx1,2)+pow(y1-ty1,2));
  1340.  
  1341.                 if (ty>0.00025) ty=sqrt(pow(x1-tx2,2)+pow(y1-ty2,2));
  1342.  
  1343.                 if (tz>0.00025) tz=sqrt(pow(x1-tx3,2)+pow(y1-ty3,2));
  1344.  
  1345.                 if (tx<0.00025 && ty<0.00025 && tz<0.00025 ) sw=1;
  1346.  
  1347.                 }
  1348.  
  1349.  
  1350.  
  1351.           if (k==10000) { /*Routines for calculating the corners*/
  1352.  
  1353.           ax=fabs(xc-xm);
  1354.  
  1355.           ay=fabs(yc-ym);
  1356.  
  1357.  
  1358.  
  1359.           if (ax<ay || fabs(ax-ay)<0.1){
  1360.  
  1361.           ax=ax*0.24;
  1362.  
  1363.           rad=ay;
  1364.  
  1365.           }
  1366.  
  1367.            else {
  1368.  
  1369.            rad=ax;
  1370.  
  1371.            ax=ax*0.075;
  1372.  
  1373.            }
  1374.  
  1375.  
  1376.  
  1377.           ay=ay*0.05;
  1378.  
  1379.           rwindow (xm-ax,ym-ay,xc+ax,yc+ay,&dx,&dy,&lx,&ly);
  1380.  
  1381.           cleardevice();
  1382.  
  1383.           setrgbpalette(1,cr[1],cg[1],cb[1]);
  1384.  
  1385.           setrgbpalette(2,cr[2],cg[2],cb[2]);
  1386.  
  1387.           setrgbpalette(3,cr[3],cg[3],cb[3]);
  1388.  
  1389.           setrgbpalette(4,cr[4],cg[4],cb[4]);
  1390.  
  1391.           setrgbpalette(255,cr[255],cg[255],cb[255]);
  1392.  
  1393.           l=0;
  1394.  
  1395.           }
  1396.  
  1397.           }
  1398.  
  1399.           /*Plotting rutines*/
  1400.  
  1401.  
  1402.  
  1403.           x2=(int)(x1*dx-lx);
  1404.  
  1405.           y2=(int)(y1*dy-ly);
  1406.  
  1407.           col=getpixel(x2,y2);
  1408.  
  1409.  
  1410.  
  1411.           /*Colour by Distance*/
  1412.  
  1413.           if (sw2==1) p=(int)((sqrt(pow(x1-x,2)+pow(y1-y,2))/rad)*255);
  1414.  
  1415.           x=x1;
  1416.  
  1417.           y=y1;
  1418.  
  1419.           /*Colour by Frecuency*/
  1420.  
  1421.           if (sw2==0) p=col+1;
  1422.  
  1423.           if (p>255) p=255;
  1424.  
  1425.           if (p<=0) p=1;
  1426.  
  1427.           if (col<p) putpixel (x2 ,y2 ,p);
  1428.  
  1429.           if (kbhit()) { sw=1; ch=getch(); }
  1430.  
  1431.           }
  1432.  
  1433.         while (sw!=1);
  1434.  
  1435.         sw=0;
  1436.  
  1437.         if (kbhit()) ch=getch();
  1438.  
  1439.         }
  1440.  
  1441.         while (ch!=27);
  1442.  
  1443.         closegraph();
  1444.  
  1445.         sw=0;
  1446.  
  1447.         gotoxy (1,3);
  1448.  
  1449.         printf ("Do you wish to continue (Y/N):\n\n");
  1450.  
  1451.         ch=getch();
  1452.  
  1453.         if (ch =='y' || ch=='Y') sw=1;
  1454.  
  1455.         }
  1456.  
  1457.         while (sw==1);
  1458.  
  1459.         clrscr();
  1460.  
  1461. }
  1462.  
  1463.  
  1464.  
  1465. double rnd(void) //* Random number generator by Mike Sargent. *//
  1466.  
  1467. {
  1468.  
  1469.    int random_integer, temp_integer;
  1470.  
  1471.    double random_double, temp_double;
  1472.  
  1473.  
  1474.  
  1475.    random_integer = random(RAND_MAX);
  1476.  
  1477.    random_double = (double)random_integer / RAND_MAX;
  1478.  
  1479.    temp_integer = random(30519);
  1480.  
  1481.    temp_double = (double)temp_integer / 1000000000L;
  1482.  
  1483.    random_double += temp_double;
  1484.  
  1485.    return(random_double);
  1486.  
  1487. }
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.