-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloweringTree.py
More file actions
71 lines (62 loc) · 2.18 KB
/
FloweringTree.py
File metadata and controls
71 lines (62 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import turtle
import random
from turtle import *
from time import sleep
static_turtle = turtle.Turtle()
frame = turtle.Screen()
def tree(branch_len, inner_turtle):
if branch_len > 3:
if 8 <= branch_len <= 12:
if random.randint(0, 2) == 0:
inner_turtle.color('snow')
else:
inner_turtle.color('lightcoral')
inner_turtle.pensize(branch_len / 3)
elif branch_len < 8:
if random.randint(0, 1) == 0:
inner_turtle.color('snow')
else:
inner_turtle.color('lightcoral')
inner_turtle.pensize(branch_len / 2)
else:
inner_turtle.color('sienna')
inner_turtle.pensize(branch_len / 10)
inner_turtle.forward(branch_len)
angle_elem = 1.5 * random.random()
inner_turtle.right(20 * angle_elem)
length_elem = 1.5 * random.random()
tree(branch_len - 10 * length_elem, inner_turtle)
inner_turtle.left(40 * angle_elem)
tree(branch_len - 10 * length_elem, inner_turtle)
inner_turtle.right(20 * angle_elem)
inner_turtle.up()
inner_turtle.backward(branch_len)
inner_turtle.down()
def petal(maxim, inner_turtle):
for i in range(maxim):
right_branch = 200 - 400 * random.random()
left_branch = 10 - 20 * random.random()
inner_turtle.up()
inner_turtle.forward(left_branch)
inner_turtle.left(90)
inner_turtle.forward(right_branch)
inner_turtle.down()
inner_turtle.color("lightcoral")
inner_turtle.circle(1)
inner_turtle.up()
inner_turtle.backward(right_branch)
inner_turtle.right(90)
inner_turtle.backward(left_branch)
if __name__ == '__main__':
static_turtle = turtle.Turtle()
my_frame = turtle.Screen()
getscreen().tracer(5, 0)
turtle.screensize(bg='wheat')
static_turtle.left(90)
static_turtle.up()
static_turtle.backward(150)
static_turtle.down()
static_turtle.color('sienna')
tree(60, static_turtle)
petal(100, static_turtle)
my_frame.exitonclick()