-
Notifications
You must be signed in to change notification settings - Fork 0
/
pohon.PY
76 lines (68 loc) · 1.43 KB
/
pohon.PY
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
72
73
74
75
76
import turtle
import math
# deklarasi untuk menggambar persegi panjang
def drawRectangle(t, width, height, color):
t.fillcolor(color)
t.begin_fill()
t.forward(width)
t.left(90)
t.forward(height)
t.left(90)
t.forward(width)
t.left(90)
t.forward(height)
t.left(90)
t.end_fill()
# deklarasi untuk menggambar segitiga
def drawTriangle(t, length, color):
t.fillcolor(color)
t.begin_fill()
t.forward(length)
t.left(135)
t.forward(length / math.sqrt(2))
t.left(90)
t.forward(length / math.sqrt(2))
t.left(135)
t.end_fill()
# deklarasi mengatur latar belakang
screen = turtle.Screen ( )
screen.bgcolor("blue")
# deklarasi turtle object
tip = turtle.Turtle ( )
tip.color ("white")
tip.shape ("turtle")
tip.speed (2)
# deklarasi dasar pohon
tip.penup()
tip.goto(100, -210)
tip.pendown()
drawRectangle(tip, 20, 40, "brown")
tip.penup()
tip.goto(100, -170)
tip.pendown()
drawRectangle(tip, 20, 40, "brown")
tip.penup()
tip.goto(100, -130)
tip.pendown()
drawRectangle(tip, 20, 40, "brown")
# deklarasi puncank pohon
tip.penup()
tip.goto(65, -90)
tip.pendown()
drawTriangle(tip, 100, "yellow")
tip.penup()
tip.goto(70, -45)
tip.pendown()
drawTriangle(tip, 80, "red")
tip.penup()
tip.goto(75, -5)
tip.pendown()
drawTriangle(tip, 70, "brown")
tip.penup()
tip.goto(80, 30)
tip.pendown()
drawTriangle(tip, 60, "green")
tip.penup()
tip.goto(85, 60)
tip.pendown()
drawTriangle(tip, 50, "blue")