-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3-1.turtle_function.py
105 lines (105 loc) · 2.76 KB
/
3-1.turtle_function.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
#======================================================================
# 3.1 turtle 모듈의 함수
#가. turtle의 움직임 관련 함수
#======================================================================
import turtle
print(turtle.position())
turtle.forward(25)
print(turtle.position())
turtle.forward(-75)
print(turtle.position())
turtle.right(45)
print(turtle.heading())
turtle.goto(150,150)
turtle.circle(100)
turtle.speed(0)
turtle.circle(150)
t2=turtle.Turtle()
print(turtle.distance(t2.pos()))
#======================================================================
#3.1 나. 펜 제어 관련 함수
#======================================================================
import turtle
turtle.pensize(1)
print(turtle.pensize())
turtle.pensize(3)
turtle.forward(100)
turtle.pencolor('pink')
turtle.forward(100)
turtle.goto(0,0)
turtle.fillcolor('green')
turtle.begin_fill()
for i in range(3):
turtle.forward(100)
turtle.right(120)
turtle.end_fill()
turtle.clear()
turtle.reset()
turtle.write("Hello Turtle",True,align="center")
turtle.write((0,0),True)
#======================================================================
#3.1 다. turtle의 상태 관련 함수와 이벤트 사용하기
#t.mainloop() 안넣어주면 뾱하고 거북이 사라짐
#======================================================================
import turtle as t
import random as r
t.shape('turtle')
def turn(x,y):
t.left(180)
def chcolor(x,y):
t.pencolor(r.choice(['red','yellow','green']))
def move(x,y):
t.goto(x,y)
t.onclick(turn)
t.onrelease(chcolor)
t.ondrag(move)
t.mainloop()
#======================================================================
#3.1 라. turtle screen 관련 함수
#======================================================================
import turtle as t
t.bgcolor('orange')
print(t.screensize())
t.screensize(1200, 1000)
def f():
t.fd(50)
t.lt(60)
t.onkey(f, "Up")
t.listen()
t.onscreenclick(t.goto)
t.mainloop()
#======================================================================
import turtle as t
t.title('ontimer test')
running = True
count=0
def f():
if running:
t.fd(50)
t.lt(60)
t.ontimer(f, 250)
global count
count += 1
if count == 6:
t.bye()
f()
t.mainloop()
#======================================================================
# 3.1 혼자서 해보기
# 5개의 원을 그려 과녁을 만드는 스크립트를 작성해보자.
#======================================================================
import turtle as t
t.bgcolor('black')
def circle(rad, col):
t.pencolor("")
t.goto(0,-(rad))
t.fillcolor(col)
t.begin_fill()
t.circle(rad)
t.end_fill()
circle(300,'white')
circle(250,'black')
circle(200,'blue')
circle(150,'red')
circle(100,'yellow')
t.mainloop()