Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mandelbrot(c,maxiter):
- z = c
- for n in range(maxiter):
- if abs(z) > 2:
- return n
- z = z*z + c
- return 0
- def julia (c,maxiter):
- z = 0
- c = complex(-0.1, 0.65)
- for n in range(maxiter):
- if abs(z) > 2:
- return n
- z = z*z + c
- return 0
- def julia_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] = julia(r1[i] + 1j*r2[j],maxiter)
- return (r1,r2,n3)
- from matplotlib import pyplot as plt
- from matplotlib import colors
- %matplotlib inline
- def julia_image(xmin,xmax,ymin,ymax,width=10,height=10,maxiter=100,cmap='hot'):
- dpi = 50
- img_width = dpi * width
- img_height = dpi * height
- x,y,z = julia_set(xmin,xmax,ymin,ymax,img_width,img_height,maxiter)
- fig, ax = plt.subplots(figsize=(width, height),dpi=50)
- ticks = np.arange(0,img_width,3*dpi)
- x_ticks = xmin + (xmax-xmin)*ticks/img_width
- plt.xticks(ticks, x_ticks)
- y_ticks = ymin + (ymax-ymin)*ticks/img_width
- plt.yticks(ticks, y_ticks)
- ax.imshow(z.T,cmap=cmap,origin='lower')
- julia_image(-2.0,2.0,-3,3,cmap='afmhot')
Add Comment
Please, Sign In to add comment