-
Notifications
You must be signed in to change notification settings - Fork 0
/
Julia Set
32 lines (29 loc) · 755 Bytes
/
Julia Set
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#Program 15b Colormap of JULIA SET, page 397
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
im_w,im_h=500, 500
c=complex(-0.1,.65)
max_abs_z=10
max_iter=1000
xmin,xmax=-2,2
xrange=xmax-xmin
ymin,ymax=-2,2
yrange=ymax-ymin
julia=np.zeros((im_w,im_h))
for re_z in range(im_w):
for im_y in range(im_h):
nit=0
#mapping pixel position to apoint in the plane
z=complex(re_z/im_w*xrange+xmin,
im_y/im_h*yrange+ymin)
#Do the iterations
while abs(z)<=max_abs_z and nit<max_iter:
z=z**2+c
nit+=1
ratio=nit/max_iter
julia[-im_y,re_z]=ratio #set axes to Re(z) and Im(z).
fig,ax=plt.subplots()
ax.axis('off')
ax.imshow(julia,interpolation='nearest',cmap=cm.hot)
plt.show()