30 lines
938 B
Python
30 lines
938 B
Python
import math
|
|
import random
|
|
from turtle import Turtle
|
|
|
|
|
|
def draw_turtle_line(turtle, start: (float,float), end: (float, float)):
|
|
turtle.penup()
|
|
turtle.goto(start[0], start[1])
|
|
turtle.pendown()
|
|
turtle.goto(end[0], end[1])
|
|
|
|
def draw_branch(turtle, point: (float, float), angle: float, length: float):
|
|
if length > 10:
|
|
x1 = round(point[0] - math.sin(angle) * length)
|
|
y1 = round(point[1] + math.cos(angle) * length)
|
|
draw_turtle_line(turtle, point, (x1, y1))
|
|
|
|
bend_angle = math.radians(random.uniform(-10, 10))
|
|
branch_angle = math.radians(random.uniform(-40, 40))
|
|
draw_branch(turtle,(x1, y1), bend_angle - branch_angle, length *
|
|
random.uniform(0.6, 0.8))
|
|
draw_branch(turtle,(x1, y1), bend_angle + branch_angle, length *
|
|
random.uniform(0.6, 0.8))
|
|
|
|
sophia = Turtle()
|
|
draw_branch(sophia, (0, 0), 0.0 ,100)
|
|
|
|
sophia.screen.mainloop()
|
|
|