Welcome, guest | Sign In | My Account | Store | Cart
```# Mandelbrot fractal
# FB - 201003254
from PIL import Image
# drawing area
xa = -2.0
xb = 1.0
ya = -1.5
yb = 1.5
maxIt = 255 # max iterations allowed
# image size
imgx = 512
imgy = 512
image = Image.new("RGB", (imgx, imgy))

for y in range(imgy):
zy = y * (yb - ya) / (imgy - 1)  + ya
for x in range(imgx):
zx = x * (xb - xa) / (imgx - 1)  + xa
z = zx + zy * 1j
c = z
for i in range(maxIt):
if abs(z) > 2.0: break
z = z * z + c
image.putpixel((x, y), (i % 4 * 64, i % 8 * 32, i % 16 * 16))

image.save("mandel.png", "PNG")
```

#### Diff to Previous Revision

```--- revision 1 2010-03-25 19:03:34
+++ revision 2 2010-03-26 04:39:46
@@ -1,7 +1,6 @@
-# mandel.py
# Mandelbrot fractal
-# FB - 201003147
-import PIL # Python Image Library
+# FB - 201003254
+from PIL import Image
# drawing area
xa = -2.0
xb = 1.0
@@ -12,20 +11,16 @@
imgx = 512
imgy = 512
image = Image.new("RGB", (imgx, imgy))
-d = ImageDraw.Draw(image)

for y in range(imgy):
-    zy = y * (yb - ya) / imgy  + ya
+    zy = y * (yb - ya) / (imgy - 1)  + ya
for x in range(imgx):
-        zx = x * (xb - xa) / imgx  + xa
+        zx = x * (xb - xa) / (imgx - 1)  + xa
z = zx + zy * 1j
c = z
for i in range(maxIt):
if abs(z) > 2.0: break
z = z * z + c
-        r = i % 4 * 64
-        g = i % 8 * 32
-        b = i % 16 * 16
-        d.point((x, y), b * 65536 + g * 256 + r)
+        image.putpixel((x, y), (i % 4 * 64, i % 8 * 32, i % 16 * 16))

image.save("mandel.png", "PNG")
```