fork download
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. def draw_tree(x, y, angle, length, depth):
  5. if depth == 0:
  6. return
  7.  
  8. x_end = x + length * np.cos(angle)
  9. y_end = y + length * np.sin(angle)
  10.  
  11. plt.plot([x, x_end], [y, y_end], color='black', lw=1)
  12.  
  13. draw_tree(x_end, y_end, angle + np.pi/6, length * 0.7, depth - 1)
  14. draw_tree(x_end, y_end, angle - np.pi/6, length * 0.7, depth - 1)
  15.  
  16. plt.figure(figsize=(6, 6))
  17. plt.axis('off')
  18. plt.axis('equal')
  19.  
  20. draw_tree(0, 0, np.pi/2, 1, 8)
  21.  
  22. plt.show()
Success #stdin #stdout #stderr 3.58s 68672KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Fontconfig error: No writable cache directories