My turtle

Rainbow

 

Task: Build rainbow


Code:

from turtle import *
k=2
xf=-530
yf=-370
speed(0)
#red orange yellow green cyan blue ,'violet'):
bgcolor('light blue')
for colir in ('red','orange','yellow','green','cyan','blue','violet','light blue'):
    dot(600,colir)
    setheading(270)
    forward(20)

penup()
goto(-800,0)
pendown()
color('dark green')
begin_fill()
goto(800,0)
goto(800,-500)
goto(-800,-500)
goto(-800,0)
end_fill()

def flower(k, xf, yf):
    #flower stem with leaves
    penup()
    goto(xf, yf)
    pendown()
    pencolor("light green")
    pensize(10/k)
    setheading(60)
    circle(250/k,20)
    setheading(60)
    fillcolor("green")
    begin_fill()
    circle(190/k,90)
    lt(90)
    circle(190/k,90)
    end_fill()
    setheading(60)
    circle(250/k,20)
    setheading(340)
    fillcolor("green")
    begin_fill()
    circle(190/k,90)
    lt(90)
    circle(190/k,90)
    end_fill()
    setheading(60)
    circle(190/k,90)
    #flower head
    col=("coral", "orangered", "magenta", "red", "crimson", "violet")     
    for i in range(12):
        pendown()
        pencolor("white")
        pensize(4/k)
        fillcolor(col[i%6])
        begin_fill()
        circle(190/k-i/2,90)
        lt(90)
        circle(190/k-i/3,90)
        end_fill()
        lt(60)
    dot(100/k,'yellow')
    
for i in range(5):
    k=k*5/4
    xf=xf+550/k
    yf=yf+240/k
    flower(k, xf, yf)

hideturtle()
mainloop()

2026-07-09 09:42:36

Comments

No comments yet. Be the first to leave one!

Leave a Comment