Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. '''
  2. Barnsley fern
  3. '''
  4.  
  5. import time
  6. import numpy as np
  7. import pylab as plt
  8. import matplotlib
  9. matplotlib.use('Agg')
  10.  
  11. ax_lims = [-6,-0.5,6,9.0]
  12.  
  13. M1 = np.array([[0,0],[0,0.16]])
  14. M2 = np.array([[0.85,0.04],[-0.04,0.85]])
  15. M3 = np.array([[0.20,-0.26],[0.23,0.22]])
  16. M4 = np.array([[-0.15,0.28],[0.26,0.24]])
  17. def T1(x): return M1@x
  18. def T2(x): return M2@x+np.array([0,1.6])
  19. def T3(x): return M3@x+np.array([0,1.6])
  20. def T4(x): return M4@x+np.array([0,0.44])
  21. Ts = [T1,T2,T3,T4]
  22.  
  23. X = np.zeros((2,10**6))
  24.  
  25. for k in range(X.shape[1]-1):
  26. X[:,k+1] = Ts[np.random.randint(0,4)](X[:,k])
  27.  
  28. # [xmin, xmax, ymin, ymax]
  29. ax_lims = [X[0,:].min()-0.5, X[0,:].max()+0.5,
  30. X[1,:].min()-0.5,X[1,:].max()+0.5]
  31.  
  32. t = [int(k) for k in np.round(2**np.linspace(0,19.9315,100) )]
  33. for k in t:
  34. fig=plt.figure(figsize=(8,8))
  35. ax = plt.gca()
  36. ax.set_facecolor('k')
  37. ax.set_xticks([])
  38. ax.set_yticks([])
  39. plt.plot(X[0,0:k+1],X[1,0:k+1],'.',ms=1,c='#39ff14')
  40. plt.axis(ax_lims)
  41.  
  42. plt.savefig('./t'+str(k+1)+'.png',dpi=100,facecolor='k')
  43. plt.close(fig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement