-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPentab.py
84 lines (69 loc) · 1.93 KB
/
Pentab.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
77
78
79
80
81
82
83
84
import numpy as np
import turtle as t
win = t.getscreen()
win.setup(600,600)
win.bgcolor("black")
win.title("Pentab")
win.listen()
pen = t.Turtle()
pen.color("white")
pen.speed(0)
t.ht()
"""
Use (CTRL + ]) to indent rightward and (CTRL + [) to indent leftward
"""
def pentab():
def pencil(x,y):
pen.ondrag(None)
pen.seth(pen.towards(x,y))
pen.goto(x,y)
pen.ondrag(pencil)
def move(x,y):
pen.up()
pen.goto(x,y)
pen.down()
def eraser():
for i in range(10):
pen.undo()
def pencolor():
colors=np.array(["red","blue","lime","white","maroon","cyan","fuchsia","gold"])
color = np.random.choice(colors)
pen.color(color)
def star():
for i in range(5):
pen.fd(100)
pen.lt(144)
def triangle():
for i in range(3):
pen.fd(100)
pen.lt(120)
def square():
for i in range(4):
pen.fd(100)
pen.lt(90)
def pentagon():
for i in range(5):
pen.fd(100)
pen.lt(72)
def hexagon():
for i in range(6):
pen.fd(100)
pen.lt(60)
def invoke():
pen.ondrag(pencil)
win.onclick(move,btn=1)
win.onclick(lambda x,y: pen.clear(),btn=3)
win.listen()
win.onkey(eraser,key="Left")
win.onkey(pencolor,key="@")
win.onkey(lambda: pen.circle(75),"c")
win.onkey(lambda: pen.fd(100),"l")
win.onkey(lambda: pen.dot(10),"d")
win.onkey(star,key="*")
win.onkey(triangle,key="t")
win.onkey(square,key="s")
win.onkey(pentagon,key="p")
win.onkey(hexagon,key="h")
invoke()
pentab()
t.mainloop()