-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb_tree.py
More file actions
43 lines (36 loc) · 755 Bytes
/
b_tree.py
File metadata and controls
43 lines (36 loc) · 755 Bytes
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
import turtle as t
from math import acos, degrees
t.screensize(10000, 10000, "white")
t.pencolor("black")
t.pensize(5)
t.setheading(-90)
t.penup()
t.speed(0)
def make_tree(pos, h):
if h == 0:
return
l = (75**2 + (2**h * 10 / 2)**2)**0.5
angle = degrees(acos(75 / l))
t.setpos(pos)
t.seth(-90)
t.left(angle / 2)
t.pendown()
t.forward(l)
t.dot(10, "black")
right_pos = t.pos()
t.back(l)
t.right(angle)
t.forward(l)
t.dot(10, "black")
left_pos = t.pos()
t.penup()
make_tree(right_pos, h - 1)
make_tree(left_pos, h - 1)
h = int(input("Select height: "))
origin = t.Vec2D(0.00, h * 100.00)
t.setpos(origin)
t.pendown()
t.dot(10)
t.penup()
make_tree(origin, h)
t.mainloop()