코드:
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
|
import turtle
t = turtle.Turtle()
t.speed(50)
t.up()
t.goto(0,-200)
t.down()
t.fillcolor("red")
t.begin_fill()
t.circle(250)
t.end_fill()
x = 50;
t.up()
t.goto(0,-100 - x)
t.down()
t.fillcolor("white")
t.begin_fill()
t.circle(200)
t.end_fill()
t.up()
t.goto(0,-50-x)
t.down()
t.fillcolor("red")
t.begin_fill()
t.circle(150)
t.end_fill()
t.up()
t.goto(0,0-x)
t.down()
t.fillcolor("blue")
t.begin_fill()
t.circle(100)
t.end_fill()
t.up()
t.goto(-85,70-x)
t.fillcolor("white")
t.begin_fill()
a = 170
t.forward(a)
t.left(144)
t.forward(a)
t.left(144)
t.forward(a)
t.left(144)
t.forward(a)
t.left(144)
t.forward(a)
t.left(144)
t.end_fill()
|
cs |
실행결과:
설명:
t = turtle.Turtle()
turtle객체의 메소드인 Turtle()함수를 이용하여 trutle을 생성 후 변수 t에 저장.
t.speed(50)
t의 그리기 속도
t.up()
up()함수를 이용하여 t를 도화지에서 뗀다(?) : 그려지지 않음.
t.goto(0,-200)
해당 좌표로 이동
t.down()
down()함수를 이용하여 t를 도화지에 다시 붙인다. : 그려짐
t.fillcolor("red")
fillcolor()함수를 이용해서 빨간색으로 칠할 준비
t.begin_fill()
begin_fill()함수를 이용해서 색칠 시작
t.circle(200)
circle()함수를 이용해서 반지름이 200인 원 그리기
t.end_fill()
end_fill()함수를 이용해서 색칠 끝