오륜기 그리기

2023. 10. 19. 19:54학교 수업/파이썬프로그래밍

import turtle

def color_fill():
    position=[[0,0,'blue'],[-120,0,'purple'],\
              [60,60,'red'],[-60,60,'yello'],[-180,60,'green']]
    
    for x,y,c in position:
        t.penup()
        t.goto(x,y)
        t.pendown
        t.color(c,c)
        t.begin_fill()
        t.circle(30)
        t.end_fill()
t=turtle.Turtle()
color_fill()

- 오륜기가 안그려지고 삼륜기가 그려지는 문제 발생

 

배운 것

- 다중 리스트를 이용해 원이 그려질 위치 좌표를 설정하기

- x,y,c지정 후 반복문 사용(리스트의 순서대로 돌아감)

- goto함수는 (x,y)를 이동시키는 것

- t.penup ~ t.pendown은 이동하는 과정에 사용

- t.color 색 선택

- t.begin_fill 색 채우기

- t.circle(30) 원을 그리며 색 채우기

- t.end_fill 색 채우기 마무리