Created
September 22, 2015 15:10
-
-
Save firstspring1845/4e958d673c51f1fe6f8f to your computer and use it in GitHub Desktop.
draw Mandelbrot set / requires PIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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