-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl_dragging_With_Color.py
134 lines (87 loc) · 2.38 KB
/
Control_dragging_With_Color.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import turtle
turtle.shapesize(3,3,3)
turtle.pensize(5)
turtle.speed(0)
def colorChangeR():
turtle.pencolor('red')
def colorChangeB():
turtle.pencolor('blue')
def colorChangeG():
turtle.pencolor('green')
def colorChangeP():
turtle.pencolor('purple')
def eraser():
# turtle.pensize(50)
turtle.pencolor('white')
global size
size = 5
def incrPenSize():
global size
turtle.pensize(size)
size = size+5
def dcrPenSize():
global size
turtle.pensize(size)
if size>5:
size = size-5
def onDrag(x,y):
turtle.ondrag(None) # don't do backtracking
turtle.goto(x,y)
turtle.ondrag(onDrag) # add new position
def mouseClick(x,y):
turtle.penup()
turtle.goto(x,y)
turtle.pendown()
turtle.listen()
turtle.onkey(colorChangeR,'r')
turtle.onkey(colorChangeB,'b')
turtle.onkey(colorChangeG,'g')
turtle.onkey(colorChangeP,'p')
turtle.onkey(eraser, '0')
turtle.onkey(incrPenSize, 'Up')
turtle.onkey(dcrPenSize, 'Down')
turtle.ondrag(onDrag) # for dragging
turtle.onscreenclick(mouseClick) # for mouse click
turtle.mainloop()
# import turtle
# turtle.shapesize(3,3,3)
# turtle.pensize(5)
# turtle.bgcolor('black')
# turtle.pencolor('white')
# turtle.speed(0)
# def changeColorR():
# turtle.pencolor('red')
# def changeColorG():
# turtle.pencolor('green')
# def changeColorB():
# turtle.pencolor('blue')
# def changeDefault():
# turtle.pencolor('white')
# def onDrag(x,y):
# turtle.ondrag(None) # don't do backtracking
# turtle.goto(x,y)
# turtle.ondrag(onDrag) # add new position
# def mouseClick(x,y):
# turtle.penup()
# turtle.goto(x,y)
# turtle.pendown()
# key='R'
# turtle.listen()
# turtle.onkey(changeDefault, '0')
# turtle.onkey(changeColorR,'r')
# turtle.onkey(changeColorB,'b')
# turtle.onkey(changeColorG,'g')
# turtle.ondrag(onDrag) # for dragging
# turtle.onscreenclick(mouseClick) # for mouse click
# turtle.mainloop()
# # def changeColor():
# # # if key=='R':
# # turtle.pencolor('red')
# # if key == 'O':
# # turtle.color('Orange')
# # if key == 'B':
# # turtle.color('Black')
# # if key == 'U':
# # turtle.color('Blue')
# # if key == 'P':
# # turtle.color('Pink')