Data Analysis/Python Basic

[파이썬] 터틀 프로그램으로 무지개색 원 그리기

뉴욕킴 2023. 3. 24. 00:03

import turtle

swidth, sheight = 500,500 #전역 변수 부분

turtle.title('무지개색 원그리기')
turtle.shape('turtle')
turtle.setup(width=swidth+50, height=sheight+50)
turtle.screensize(swidth, sheight)
turtle.penup()
turtle.goto(5,-sheight/2)

for radius in range(1,250):
    if radius % 6==0:
        turtle.pencolor('red')
    elif radius % 5 ==0:
        turtle.pencolor('orange')
    elif radius % 4 ==0:
        turtle.pencolor('yellow')
    elif radius % 3 ==0:
        turtle.pencolor('green')
    elif radius % 2 ==0:
        turtle.pencolor('blue')
    elif radius % 1 ==0:
        turtle.pencolor('navyblue')
    else:
        turtle.pencolor('purple')

 

 

 

turtle — 터틀 그래픽 — Python 3.11.2 문서

 

turtle — Turtle graphics

Source code: Lib/turtle.py Introduction: Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzeig, Sey...

docs.python.org