Skip to content

Instantly share code, notes, and snippets.

@firstspring1845
Created September 22, 2015 15:10
Show Gist options
  • Save firstspring1845/4e958d673c51f1fe6f8f to your computer and use it in GitHub Desktop.
Save firstspring1845/4e958d673c51f1fe6f8f to your computer and use it in GitHub Desktop.
draw Mandelbrot set / requires PIL
import itertools
from PIL import Image
#def mandel(z, c):
# return z ** 2 + c
result = Image.new("L", (400, 400))
for r, i in itertools.product(xrange(400), repeat=2):
c = complex(r / 100.0 - 2.0, i / 100.0 - 2.0)
z = 0
print c
result.putpixel((r, i), 255)
for cnt in xrange(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