Skip to content

Instantly share code, notes, and snippets.

@utgwkk
Forked from firstspring1845/mandel.py
Last active October 23, 2015 11:23
Show Gist options
  • Save utgwkk/83691138e85b5a65bdcb to your computer and use it in GitHub Desktop.
Save utgwkk/83691138e85b5a65bdcb to your computer and use it in GitHub Desktop.
draw Mandelbrot set / requires PIL
import itertools
from PIL import Image
result = Image.new("L", (6400, 6400))
for r, i in itertools.product(range(6400), repeat=2):
c = complex(r / 1600.0 - 2.0, i / 1600.0 - 2.0)
z = 0
print(c)
result.putpixel((r, i), 255)
for cnt in range(50):
z = z ** 2 + c
if not (-2 < z.real < 2) or not (-2 < z.imag < 2):
result.putpixel((r, i), int(cnt * 5.12))
break
result.save('mandel.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment