import numpy as np
import matplotlib.pyplot as plt
def create_branch(start, angle, length, depth, max_depth):
if depth > max_depth:
return
end = start + length * np.array([np.cos(angle), np.sin(angle)])
plt.plot([start[0], end[0]], [start[1], end[1]], color='green', alpha=0.15)
if depth < max_depth:
num_branches = np.random.randint(1, 4)
for _ in range(num_branches):
new_angle = angle + np.random.uniform(-0.5, 0.5)
new_length = length * np.random.uniform(0.6, 0.9)
create_branch(end, new_angle, new_length, depth + 1, max_depth)
plt.figure(figsize=(10, 10))
for plot_num in range(16):
np.random.seed(plot_num)
plt.subplot(4, 4, plot_num+1)
num_main_branches = np.random.randint(5, 10)
for i in range(num_main_branches):
angle = 0.1 * np.pi * i/num_main_branches + 0.45*np.pi
length = np.random.uniform(0.1, 0.25)
create_branch([0, 0], angle, length, 0, max_depth=8)
plt.gca().set_aspect('equal', adjustable='box')
plt.axis('off')
plt.show()