Created
February 15, 2018 12:54
-
-
Save M-Barnett/164338a18bf92b61a254a15a00c9ec69 to your computer and use it in GitHub Desktop.
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 numpy as np | |
import matplotlib.pyplot as plt | |
class Mandelbrot(object): | |
def __init__(self): | |
n = 500 | |
self.n = n | |
self.grid = np.zeros((n,n)) | |
x = np.linspace(-2.025, 0.6, n) | |
y = np.linspace(-1.125, 1.125, n) | |
self.xx, self.yy = np.meshgrid(x,y) | |
def establishComplex(self, Re, Im): | |
c = complex(Re, Im) | |
z = 0.0j | |
maxiter = 255 | |
for i in range(maxiter): | |
z = z * z + c | |
if abs(z) >= 2: | |
return i | |
return maxiter | |
def generate(self): | |
for i in range(self.n): | |
for j in range(self.n): | |
Re = self.xx[j,i] | |
Im = self.yy[j,i] | |
result = self.establishComplex(Re, Im) | |
self.grid[i,j] = result | |
def plotSet(self): | |
plt.figure(dpi = 100) | |
plt.imshow(self.grid.T,cmap='hot',interpolation='none',extent=[-2.025, 0.6, -1.125, 1.125]) | |
plt.title('mandelbrot set') | |
plt.xlabel('Re') | |
plt.ylabel('Im') | |
plt.show | |
def main(): | |
m = Mandelbrot() | |
m.generate() | |
m.plotSet() | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment