I have this code:
from PIL import Image
import colorsys
xmin, xmax = -2.0, 2.0
ymin, ymax = -2.0, 2.0
depth = 12
imgx, imgy = 512, 512
maxIter = 256
image = Image.new("RGB", (imgx, imgy))
for y in range(imgy):
cy = y * (ymax - ymin)/(imgy - 1) + ymin
for x in range(imgx):
cx = x * (xmax - xmin)/(imgx - 1) + xmin
c = complex(cx, cy)
z = 0
for i in range(maxIter):
if abs(z) > 2.0:
break
z = c + complex(0.25, 0.1)
r = i
g = int((i*50)%256)
b = int(255 - i)
image.putpixel((x, y), (r, g, b))
It creates an image of a circle (image below), and I can't understand why. I think it might have something to do with the for loops and the if statements, but I can't figure out what the problem would be. If it's not that, what is it?
Side note: this code is adapted from a Mandelbrot set code I wrote. The only difference is that instead of z = c + complex(0.25, 0.1),
I have z = z**2 + c.
This line:
z = c + complex(0.25, 0.1)
always yields the same value (current point + a constant) in each iteration, so your code just draws a circle. Change that line to
z = z**2 + complex(0.25, 0.1)
and initialize z
based on the current point (like c
is in your current code).