Created
April 20, 2014 10:15
-
-
Save scturtle/11110463 to your computer and use it in GitHub Desktop.
Mandelbrot demo
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
''' http://nbviewer.ipython.org/gist/anonymous/f5707335f40af9463c43 ''' | |
try: | |
import numpy as np | |
except: | |
import numpypy as np | |
def mandel(x, y, max_iters): | |
c = complex(x, y) | |
z = 0.0j | |
for i in xrange(max_iters): | |
z = z * z + c | |
if (z.real * z.real + z.imag * z.imag) >= 4: | |
return i | |
return max_iters | |
def create_fractal(min_x, max_x, min_y, max_y, image, iters): | |
height, width = image.shape | |
pixel_size_x = (max_x - min_x) / width | |
pixel_size_y = (max_y - min_y) / height | |
for x in xrange(width): | |
real = min_x + x * pixel_size_x | |
for y in xrange(height): | |
imag = min_y + y * pixel_size_y | |
color = mandel(real, imag, iters) | |
image[y, x] = color | |
image = np.zeros((1024, 1536), dtype=np.uint8) | |
create_fractal(-2.0, 1.0, -1.0, 1.0, image, 20) | |
from matplotlib.pyplot import imshow, show | |
imshow(image) | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment