-
[turtle] 파이썬으로 다중원 그려서 과녁 모양 만드는 프로그램Programming/Python 2022. 4. 10. 17:39
*while문을 쓰지 않는 경우
다중원을 그려서 과녁 모양이 되게 합시다.
전체 알고리즘:
바깥쪽부터 안쪽으로 원을 그리고
filcolor()를 사용하여 차례대로 검정, 흰색을 반복해서 칠한다.
penup()인 상태에서는 그림이 그려지지 않으며
setposition()으로 turtle의 위치를 재조정한다.
pendown()으로 다시 그림을 그리기 시작한다
begin_fill()로는 색을 칠하기 시작하며
end_fill()로는 색을 칠하는 것을 끝낸다
import turtle t = turtle.Turtle() t.speed(20) t.pencolor("white") t.fillcolor("black") #제일 바깥 5 t.begin_fill() t.circle(75) t.end_fill() #4 t.penup() t.setposition((0, 15)) t.pendown() t.fillcolor("white") t.begin_fill() t.circle(60) t.end_fill() #3 t.penup() t.setposition((0, 30)) t.pendown() t.fillcolor("black") t.begin_fill() t.circle(45) t.end_fill() #2 t.penup() t.setposition((0, 45)) t.pendown() t.fillcolor("white") t.begin_fill() t.circle(30) t.end_fill() #1 t.penup() t.setposition((0, 60)) t.pendown() t.fillcolor("black") t.begin_fill() t.circle(15) t.end_fill() turtle.exitonclick() #클릭시 종료되게 함
실행결과 화면 IDE는 파이참을 사용했고, 계속 turtle창이 꺼져서 마지막에 exitonclick()를 추가하였다.
참고 사이트 : https://medium.com/analytics-vidhya/part-2-turtle-in-python-8708e2ba68f5
'Programming > Python' 카테고리의 다른 글
[PyScript] html에서 파이썬 코드 실행하는 프레임워크 (0) 2022.05.23 [OpenCV] 노트북 캠 스트리밍 하기 (0) 2022.05.19 [문제풀이] 정수를 입력받아서 한 자리씩 출력하는 프로그램 (0) 2022.04.10 [Matlab] 기본 정리 (0) 2022.03.26 [pandas] 기초 입문 1 - 데이터프레임, 시리즈 (0) 2022.03.08