Skip to content

Instantly share code, notes, and snippets.

@mechamug
Created February 26, 2020 20:03
Show Gist options
  • Save mechamug/f6263f794c800eb39e4311cb8f3a5824 to your computer and use it in GitHub Desktop.
Save mechamug/f6263f794c800eb39e4311cb8f3a5824 to your computer and use it in GitHub Desktop.
from numba import jit
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
@jit
def mandelbrot(c,maxiter):
z = c
la = 0
t = 16
for n in range(maxiter):
if abs(z) > t:
#d = (4 - abs(z))
#r = np.random.normal(scale=0.5)
d = (t - abs(z)) * abs(np.random.rand()) / t / 8
#i = n + d
#return i #np.sqrt(i)
return abs(z) / maxiter
z = z*z + c
la = abs(z)
d = abs(np.random.rand())
i = abs(np.angle(z)) / np.pi * maxiter + d
return i
@jit
def mandelbrot_set(xmin,xmax,ymin,ymax,width,height,maxiter):
r1 = np.linspace(xmin, xmax, width)
r2 = np.linspace(ymin, ymax, height)
n3 = np.empty((width,height))
for i in range(width):
for j in range(height):
n3[i,j] = mandelbrot(r1[i] + 1j*r2[j],maxiter)
return (r1,r2,n3)
import sys
for cmap in sys.argv[1:]:
file = f'numba-plot-{cmap}.png'
_,_,n3 = mandelbrot_set(-1.5,1.5,-1.2,1.2,800,600,100)
plt.imsave(file, n3.T, cmap= cm.get_cmap(cmap,10000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment