Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Barnsley fern
- '''
- import time
- import numpy as np
- import pylab as plt
- import matplotlib
- matplotlib.use('Agg')
- ax_lims = [-6,-0.5,6,9.0]
- M1 = np.array([[0,0],[0,0.16]])
- M2 = np.array([[0.85,0.04],[-0.04,0.85]])
- M3 = np.array([[0.20,-0.26],[0.23,0.22]])
- M4 = np.array([[-0.15,0.28],[0.26,0.24]])
- def T1(x): return M1@x
- def T2(x): return M2@x+np.array([0,1.6])
- def T3(x): return M3@x+np.array([0,1.6])
- def T4(x): return M4@x+np.array([0,0.44])
- Ts = [T1,T2,T3,T4]
- X = np.zeros((2,10**6))
- for k in range(X.shape[1]-1):
- X[:,k+1] = Ts[np.random.randint(0,4)](X[:,k])
- # [xmin, xmax, ymin, ymax]
- ax_lims = [X[0,:].min()-0.5, X[0,:].max()+0.5,
- X[1,:].min()-0.5,X[1,:].max()+0.5]
- t = [int(k) for k in np.round(2**np.linspace(0,19.9315,100) )]
- for k in t:
- fig=plt.figure(figsize=(8,8))
- ax = plt.gca()
- ax.set_facecolor('k')
- ax.set_xticks([])
- ax.set_yticks([])
- plt.plot(X[0,0:k+1],X[1,0:k+1],'.',ms=1,c='#39ff14')
- plt.axis(ax_lims)
- plt.savefig('./t'+str(k+1)+'.png',dpi=100,facecolor='k')
- plt.close(fig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement