I'm currently writing a Mandelbrot program in python. In one implementation, I used python's complex number type. In the other, I implemented complex numbers as two separate numbers (I think I have an error there). I don't understand why the two programs output a different-looking result since they should both do the same thing (unless I have some stupid error in my code). Could someone tell me why this is happening (and possibly what I did wrong), and how I can fix this?
This is my code:
size = 40
for y in range(size):
for x in range(size*2):
c = complex(x / (size / 2) - 2, y / (size / 4) - 2)
z = complex(0, 0)
i = 0;
while i < 100:
z = z**2 + c
if abs(z) > 2:
break
i+=1
if i == 100:
print("#", end="")
elif i > 10:
print(".", end="")
else:
print(" ", end="")
print()
#########################
size = 40
for y in range(size):
for x in range(size*2):
cx = x / (size / 2) - 2
cy = y / (size / 4) - 2
zx = 0
zy = 0
i = 0
while i < 100:
zx = (zx * zx - zy * zy) + cx
zy = (2 * zx * zy) + cy
if zx * zx + zy * zy > 4:
break
i+=1
if i == 100:
print("#", end="")
elif i > 10:
print(".", end="")
else:
print(" ", end="")
print()
The upper Implementation prints this:
.
#
..
.####.
.####. .
..#..##########......
...#################.
. .###################. .
...... .#####################.
.#######..######################.
....#########.######################
##############################################.
....#########.######################
.#######..######################.
...... .#####################.
. .###################. .
...#################.
..#..##########......
.####. .
.####.
..
#
.
And the lower one prints this:
# . .
..#####.. . ..
############# ... .
. #################.
. #. #################### #
.#### . .#######################
#######..###########################.
##################################.
#######################################
#####################################
##############################################.
#####################################
#######################################
##################################.
#######..###########################.
.#### . .#######################
. #. #################### #
. #################.
############# ... .
..#####.. . ..