home *** CD-ROM | disk | FTP | other *** search
/ Pulse 2 / pulse-2.zip / JULIA.C < prev    next >
C/C++ Source or Header  |  1993-05-04  |  1KB  |  64 lines

  1. /* Unoptimized version. Draws a Julia picture. Check the code for variables
  2.    to modify if you want other pictures. */
  3.  
  4. #include <graphics.h>
  5.  
  6. main()
  7. {
  8.   int g_driver = 9, g_mode = 2; /* VGA-16 col, 640x480 */
  9.   int count, i;
  10.   float r0, r1, i0, i1, zreal, zimag, ztemp, zsize, m, n, cr, ci;
  11.  
  12.   /* Set up the graphics and colors. */
  13.  
  14.   initgraph(&g_driver, &g_mode, "");
  15.  
  16.   for(i = 0; i < 16; ++i)
  17.   {
  18.     setrgbpalette(i,0,i*2,i*4);
  19.     setpalette(i,i);
  20.   }
  21.  
  22.   /* Change these values for different parts of the current Julia Set. */
  23.  
  24.   r0 = -2.0; r1 = 2.0;
  25.   i0 = 1.5; i1 = -1.5;
  26.  
  27.   /* Change these values for different Julia Sets. Check out JULIA.EXS for
  28.      some examples. */
  29.  
  30.   cr = 0.32; ci = 0.043;
  31.  
  32.   for(n = 0; n < 480; ++n)
  33.   {
  34.     for(m = 0; m < 480; ++m)
  35.     {
  36.       zreal = r0 + ((r1-r0)*m)/480;
  37.       zimag = i0 + ((i1-i0)*n)/480;
  38.  
  39.       for(count = zsize = 0; ((count < 256) && (zsize < 10000.0)); ++count)
  40.       {
  41.         ztemp = zreal;
  42.         zreal = zreal*zreal - zimag*zimag + cr;
  43.         zimag = 2*ztemp*zimag + ci;
  44.         zsize = zreal*zreal + zimag*zimag;
  45.       }
  46.  
  47.       if (count != 256)
  48.         putpixel(m+80, n, count%15 + 1);
  49.  
  50.       if (kbhit())
  51.       {
  52.         closegraph();
  53.         return(0); /* Yes, close up and leave. */
  54.       }
  55.     }
  56.   }
  57.   /* Picture done. Wait for key, then shut down the graphics and leave
  58.      the program. */
  59.   getch();
  60.   closegraph();
  61.   return(0);
  62. }
  63.  
  64.