본문 바로가기

프로그램언어/파이썬

무지개색 원그리기

거북이로 무지개색 원을 그리기

 

 

소스코드

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(0, -sheight / 2)

turtle.pendown()

turtle.speed(10)  ## 0:가장빠름, 10:빠름, 6:정상, 3:느림, 1:가장느림 ##

 

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.circle(radius)

 

turtle.done()