Created
March 3, 2010 02:37
-
-
Save mlaprise/320241 to your computer and use it in GitHub Desktop.
Generate a representation of the Mandelbrot Set
This file contains hidden or 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
from numpy import * | |
import matplotlib.pylab as pl | |
maxIteration = 128 | |
z_min = -2-1j | |
z_max = 1+1j | |
# Set the image size here | |
imageSize = [512,512] | |
image = zeros(imageSize,int) | |
xValue = linspace(z_min.real, z_max.real, imageSize[0]) | |
yValue = linspace(z_min.imag, z_max.imag, imageSize[1]) | |
for i in arange(imageSize[0]): | |
for k in arange(imageSize[1]): | |
iteration = 0 | |
x = xValue[i] | |
y = yValue[k] | |
while (x*x+y*y < (2*2)) & (iteration < maxIteration): | |
xtemp = x*x - y*y + xValue[i] | |
y = 2*x*y + yValue[k] | |
x = xtemp | |
iteration = iteration + 1 | |
if iteration == maxIteration: | |
image[i,k] = 0 | |
else: | |
image[i,k] = 255-iteration | |
pl.imshow(image) | |
pl.prism() | |
pl.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment