Julia sets

on 17 Oct 2010 by Mukund (@muks)

ender in #gimp said he likes Julias better. For what it's worth, the code from yesterday can also generate Julia sets with a tiny modification.

Julia Set 1 Julia Set 2

--- mandel.c 2010-10-16 21:45:13.000000000 +0530
+++ julia.c   2010-10-17 22:16:53.000000000 +0530
@@ -6,9 +6,9 @@
 
 /* Boundaries of the set */
 
-#define X1 -2.0
-#define X2  1.0
-#define Y1 -1.2
+#define X1 -1.6
+#define X2  1.6
+#define Y1 -1.0
 #define Y2  1.0
 
 /* Dimensions of the output PPM in pixels */
@@ -29,6 +29,7 @@
 
   double cx, cy, zx, zy, tx;
   double dx, dy;
+  double kx, ky;
 
   int sines[256];
 
@@ -56,6 +57,9 @@
   dx = x2 - x1;
   dy = y2 - y1;
 
+  kx = -0.726895347709114071439;
+  ky = 0.188887129043845954792;
+
   for (j = 0; j < HEIGHT; j++)
     {
       cy = y1 + ((j / (HEIGHT * 1.0)) * dy);
@@ -72,8 +76,8 @@
               if (((zx * zx) + (zy * zy)) >= 4.0)
                 break;
 
-              tx = cx + ((zx * zx) - (zy * zy));
-              zy = cy + (2 * zx * zy);
+              tx = kx + ((zx * zx) - (zy * zy));
+              zy = ky + (2 * zx * zy);
               zx = tx;
             }

Download julia.patch.