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

  1. //
  2.  
  3. //+----------------------------------------------------------------------+
  4.  
  5. //+ Program DISKS.CPP                                                    +
  6.  
  7. //+ By Fausto A. A. Barbuto, BJ06@C53000.PETROBRAS.ANRJ.BR               +
  8.  
  9. //+ Rio de Janeiro, BRAZIL, on May 14, 1994.                             +
  10.  
  11. //+                                                                      +
  12.  
  13. //+ Plots six Julia sets with inner contours in shadings of gray.        +
  14.  
  15. //+                                                                      +
  16.  
  17. //+ REFERENCE: Peitgen, H.-O. & Richter, P.H.: "The Beauty of Fractals", +
  18.  
  19. //+            Springer-Verlag, 1986.                                    +
  20.  
  21. //+                                                                      +
  22.  
  23. //+ Needs SVGA256.BGI and SVGA256.H (from SVGABG50 package by Jordan     +
  24.  
  25. //+ Hargrave).                                                           +
  26.  
  27. //+                                                                      +
  28.  
  29. //+ Authorized version for spanky.triumf.ca site (Vancouver, BC, CANADA).+
  30.  
  31. //+----------------------------------------------------------------------+
  32.  
  33. //
  34.  
  35. #include <stdio.h>
  36.  
  37. #include <conio.h>
  38.  
  39. #include <graphics.h>
  40.  
  41. #include <math.h>
  42.  
  43. #include "Svga256.h"
  44.  
  45. //void far initgraph(int far *,int far *,char far *);
  46.  
  47.  
  48.  
  49. int Vid;  //Global variable
  50.  
  51.  
  52.  
  53. int huge DetectSVGA256()
  54.  
  55. {
  56.  
  57.   printf("\n Which video mode would you like to use? \n\n");
  58.  
  59.   printf(" 0 - 320x200x256\n");
  60.  
  61.   printf(" 1 - 640x400x256\n");
  62.  
  63.   printf(" 2 - 640x480x256\n");
  64.  
  65.   printf(" 3 - 800x600x256\n");
  66.  
  67.   printf(" 4 - 1024x768x256\n\n");
  68.  
  69.   printf(" (Try mode 4, if possible) \n\n > ");
  70.  
  71.   scanf("%d",&Vid);
  72.  
  73.   return Vid;
  74.  
  75. }
  76.  
  77.  
  78.  
  79. void main(void)
  80.  
  81. {
  82.  
  83.       double xmin, xmax, ymin, ymax, x, y, x0, y0, R1, I1, Temp;
  84.  
  85.       double deltax, deltay, p, q, r, a, b;
  86.  
  87.       double c1[6] = {15.0,18.0,15.0,15.0,18.0,15.0};
  88.  
  89.       double c2[6] = {1.25e+7,13.0,1.5e+3,38.0,125.0,75.0};
  90.  
  91.       register int npix, npiy, k, np, nq;
  92.  
  93.       int Maxit, ipen, index;
  94.  
  95.       int graphdriver=DETECT, graphmode;
  96.  
  97.  
  98.  
  99.       printf("\n  Program DISKS.CPP \n");
  100.  
  101.       printf("\n\n  By Fausto A. A. Barbuto, May 14, 1994");
  102.  
  103.       printf("\n  Rio de Janeiro, Federal Republic of Brazil");
  104.  
  105.       printf("\n  E-mail: BJ06@C53000.PETROBRAS.ANRJ.BR\n\n");
  106.  
  107.       printf("\n  Reference: Peitgen, H.-O., and Richter, P.H. :");
  108.  
  109.       printf("\n  'The Beauty of Fractals', Springer-Verlag, 1986\n\n");
  110.  
  111.       printf("\n                   Select a Julia set: \n\n");
  112.  
  113.       printf("   1: c = -0.123750 + 0.565080i  (Map 20, pg. 52) \n");
  114.  
  115.       printf("   2: c = -0.390540 - 0.586790i  (Map 22 & 25, pgs. 52, 77)\n");
  116.  
  117.       printf("   3: c =  0.310000 + 0.040000i  (Hmmm... Pretty good!)\n");
  118.  
  119.       printf("   4: c = -0.481762 - 0.531657i   \n");
  120.  
  121.       printf("   5: c =  0.273340 + 0.007420i  (Fausto's favourite)\n");
  122.  
  123.       printf("   6: c = -0.125000 + 0.649250i   \n");
  124.  
  125.       printf("\n> ");
  126.  
  127.       scanf("%d",&index);
  128.  
  129.       if ((index<1) || (index>6)) index = 1;
  130.  
  131.  
  132.  
  133.       if (index == 1) {xmin=-1.40;xmax=1.40;ymin=-1.4;ymax=1.4;Maxit=128;
  134.  
  135.                p=-0.123750;q= 0.565080;}
  136.  
  137.       if (index == 2) {xmin=-1.50;xmax=1.50;ymin=-1.5;ymax=1.5;Maxit=256;
  138.  
  139.                p=-0.390540;q=-0.586579;}
  140.  
  141.       if (index == 3) {xmin=-1.20;xmax=1.20;ymin=-1.2;ymax=1.2;Maxit=256;
  142.  
  143.                p= 0.310000;q= 0.040000;}
  144.  
  145.       if (index == 4) {xmin=-1.50;xmax=1.50;ymin=-1.5;ymax=1.5;Maxit=512;
  146.  
  147.                p=-0.481762;q=-0.531657;}
  148.  
  149.       if (index == 5) {xmin=-1.10;xmax=1.10;ymin=-1.1;ymax=1.1;Maxit=256;
  150.  
  151.                p= 0.273340;q= 0.007420;}
  152.  
  153.       if (index == 6) {xmin=-1.75;xmax=1.75;ymin=-1.5;ymax=1.5;Maxit=512;
  154.  
  155.                p=-0.125000;q= 0.649250;}
  156.  
  157.       clrscr();
  158.  
  159.  
  160.  
  161.       installuserdriver("Svga256",DetectSVGA256);
  162.  
  163.       initgraph(&graphdriver, &graphmode, "c:\\borlandc\\bgi");
  164.  
  165.       if (Vid == 0) {npix = 320; npiy = 200;}
  166.  
  167.       if (Vid == 1) {npix = 640; npiy = 400;}
  168.  
  169.       if (Vid == 2) {npix = 640; npiy = 480;}
  170.  
  171.       if (Vid == 3) {npix = 800; npiy = 600;}
  172.  
  173.       if (Vid == 4) {npix =1024; npiy = 768;}
  174.  
  175.       if((Vid<0) || (Vid)>4) Vid = 2;
  176.  
  177.  
  178.  
  179.       deltax = (xmax-xmin)/(npix-1);
  180.  
  181.       deltay = (ymax-ymin)/(npiy-1);
  182.  
  183.  
  184.  
  185.       cleardevice();
  186.  
  187.       for (np=0; np<=npix-1; np++) {
  188.  
  189.     x0 = xmin + (double)np*deltax;
  190.  
  191.     for (nq=0; nq<=npiy-1; nq++) {
  192.  
  193.     y0 = ymin + (double)nq*deltay;
  194.  
  195.     x = x0;
  196.  
  197.     y = y0;
  198.  
  199.     k  = 0;
  200.  
  201.  
  202.  
  203.      do {
  204.  
  205.        Temp = x*y;
  206.  
  207.        R1 = (x-y)*(x+y) + p;
  208.  
  209.        I1 = Temp + Temp + q;
  210.  
  211.        r = sqrt(R1*R1 + I1*I1);
  212.  
  213.        k++;
  214.  
  215.  
  216.  
  217.        if (r >= Maxit) {   //* Escaped points. *//
  218.  
  219.          ipen = 30 + k;
  220.  
  221.          putpixel(np,nq,ipen);
  222.  
  223.        }
  224.  
  225.  
  226.  
  227.        if (k == Maxit) {   //* Converged points. *//
  228.  
  229. //*
  230.  
  231. //*          The colour shades of the inner contours are defined here
  232.  
  233. //*          (as function of the distance between the current point [x,y]
  234.  
  235. //*          and an "invariant" point [x=R(z),y=I(z)]).
  236.  
  237. //*
  238.  
  239.          a = (x-R1)*(x-R1);
  240.  
  241.          b = (y-I1)*(y-I1);
  242.  
  243.          ipen = c1[index-1] + (int)(c2[index-1]*sqrt(a+b));
  244.  
  245.          putpixel(np,nq,ipen);
  246.  
  247.        }
  248.  
  249.  
  250.  
  251.        x = R1;
  252.  
  253.        y = I1;
  254.  
  255.      } while (r <= Maxit && k<=Maxit);
  256.  
  257.        }
  258.  
  259.        if(kbhit()) break;
  260.  
  261.      }
  262.  
  263.  
  264.  
  265.      getch();
  266.  
  267.      closegraph();
  268.  
  269. }
  270.  
  271.