-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturtle_paintboard.py
229 lines (165 loc) · 5.31 KB
/
turtle_paintboard.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# turtle_paintboard
import turtle as t
color_status = ['black', 'red', 'orange', 'yellow', 'green', 'blue', 'violet']
thickness = 1
print("<Turtle Paint-board>")
print("- 키보드 방향키로 거북이를 움직여 그림을 그려봅시다 -")
print("")
print("사용법:")
print("1. 터틀 스크린에 마우스를 클릭하면 클릭 위치로 거북이가 이동합니다.")
print("2. 거북이를 마우스로 드래그하여 움직일 수 있습니다.")
print("3. 키보드 방향키로 거북이를 움직일 수 있습니다.")
print(" - 좌 우 방향키는 거북이의 방향을 결정합니다.")
print(" - 위 아래 방향키로 거북이를 움직입니다.")
print("4. Enter키로 '선 그리기'를 활성화 혹은 비활성화 할 수 있습니다.")
print("5. Tab키로 선 굵기를 조절할 수 있습니다.")
print("6. 숫자 키로 색을 지정할 수 있습니다.")
print(" - 0: 검정 1: 빨강 2: 주황 3: 노랑 4: 초록 5: 파랑 6: 보라")
print("7. 그림을 리셋하려면 r, 프로그램을 종료하려면 q를 누르세요.")
print("8. 도형을 그리려면 스페이스바를 누르고 아래의 안내를 따르세요.")
def key_Return():
pen_status = t.isdown()
if pen_status == True:
t.penup()
print("")
print("'선 그리기' 비활성화")
else:
t.pendown()
print("")
print("'선 그리기' 활성화")
def key_Up():
t.forward(10)
def key_Down():
t.backward(10)
def key_Left():
t.left(90)
def key_Right():
t.right(90)
def color(status):
t.pencolor(color_status[status])
def key_0():
color(0)
print("")
print("검정색")
def key_1():
color(1)
print("")
print("빨간색")
def key_2():
color(2)
print("")
print("주황색")
def key_3():
color(3)
print("")
print("노란색")
def key_4():
color(4)
print("")
print("초록색")
def key_5():
color(5)
print("")
print("파란색")
def key_6():
color(6)
print("")
print("보라색")
def key_space():
print("")
print("- 도형 그리기 -")
print("shell 창에 입력하여 거북이가 도형을 그리도록 명령합니다.")
print("원을 그리려면 'circle', 정n각형을 그리고 싶다면 'other'을 입력하세요.")
print("도형 그리기를 취소하려면 'cancel'을 입력하세요.")
while True:
print("")
shape = input(" -> 여기에 입력: ")
print("")
if shape == 'circle':
print("원을 그립니다.")
while True:
radius = float(input(" -> 반지름을 입력하세요: "))
if radius < 0:
print("")
print("잘못 입력하셨습니다. 다시 입력하세요.")
print("")
continue
else:
break
t.speed(6)
t.circle(radius)
t.speed(0)
print("")
print("원을 그렸습니다!")
print("도형을 더 그리려면 스페이스바를 한번 더 누르세요.")
break
elif shape == 'other':
print("정n각형을 그립니다.")
while True:
n = int(input(" -> n을 입력하세요: "))
if n < 0:
print("")
print("잘못 입력하셨습니다. 다시 입력하세요.")
print("")
continue
else:
break
while True:
side = float(input(" -> 한 변의 길이를 입력하세요: "))
if side < 0:
print("")
print("잘못 입력하셨습니다. 다시 입력하세요.")
print("")
continue
else:
break
t.speed(3)
for i in range(n):
t.forward(side)
t.left(int(360/n))
t.speed(0)
print("")
print("정" + str(n) + "각형을 그렸습니다!")
print("도형을 더 그리려면 스페이스바를 한번 더 누르세요.")
break
elif shape == 'cancel':
print("도형 그리기를 취소하셨습니다.")
print("도형을 그리려면 스페이스바를 한번 더 누르세요.")
break
else:
print("잘못 입력하셨습니다. 다시입력하세요.")
continue
def key_Tab():
global thickness
thickness += 2
if thickness > 10:
thickness = 1
t.pensize(thickness)
print("")
print("선 굵기:", thickness)
def key_r():
t.goto(0, 0)
t.clear()
t.shape("turtle")
t.speed(0)
t.pensize(thickness)
t.ondrag(t.goto)
s = t.Screen()
s.onkey(key_Return, 'Return')
s.onkey(key_Tab, 'Tab')
s.onscreenclick(t.goto)
s.onkeypress(key_Up, 'Up')
s.onkeypress(key_Down, 'Down')
s.onkey(key_Left, 'Left')
s.onkey(key_Right, 'Right')
s.onkey(key_0, '0')
s.onkey(key_1, '1')
s.onkey(key_2, '2')
s.onkey(key_3, '3')
s.onkey(key_4, '4')
s.onkey(key_5, '5')
s.onkey(key_6, '6')
s.onkey(key_space, 'space')
s.onkey(s.bye, 'q')
s.onkey(key_r, 'r')
s.listen()