Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- from math import sin, cos, pi, sqrt
- x_list = []
- y_list = []
- def get_koch(angle, length, gen):
- if gen > 0:
- get_koch(angle, length / 3, gen - 1)
- get_koch(angle + pi / 3, length / 3, gen - 1)
- get_koch(angle - pi / 3, length / 3, gen - 1)
- get_koch(angle, length / 3, gen - 1)
- else:
- x = x_list[-1] + length * cos(angle)
- y = y_list[-1] + length * sin(angle)
- x_list.append(x)
- y_list.append(y)
- def draw_koch(angle, length, gen):
- x_list.append(-length / 2)
- y_list.append(0.25 * sqrt(1.25 * length ** 2))
- get_koch(angle, length, gen)
- get_koch(angle - 2 * pi / 3, length, gen)
- get_koch(angle + 2 * pi / 3, length, gen)
- plt.plot(x_list, y_list)
- plt.axis([-length / 1.5, length / 1.5, -length / 1.5, length / 1.5])
- plt.show()
- draw_koch(0.0, 300.0, 7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement