Day 20 - Better Flowers Using Custom Functions

In this project we will introduce custom functions as a powerful way of making our main program more concise and easier to manage.

Starter Code

from turtle import *

left(90)
color("cornflowerblue")
begin_fill()
circle(-40,60)
circle(-200,30)
circle(-25, 100)
circle(20,30)
circle(-30, 30)
circle(25,30)
circle(-20, 30)
circle(30,30)
circle(-25, 100)
circle(-200,30)
circle(-40,70)
forward(20)
end_fill()

color("yellow")
begin_fill()
right(60)
circle(-300,20)
right(170)
circle(300,15)
right(200)
circle(-300,20)
right(170)
circle(300,25)
right(200)
circle(-300,20)
right(170)
circle(300,20)
right(90)
circle(-200,15)
end_fill()

done()

Finished Code

from turtle import *

speed(0)

def draw_petal(strColor1,strColor2):
    left(90)
    color(strColor1)
    begin_fill()
    circle(-40,60)
    circle(-200,30)
    circle(-25, 100)
    circle(20,30)
    circle(-30, 30)
    circle(25,30)
    circle(-20, 30)
    circle(30,30)
    circle(-25, 100)
    circle(-200,30)
    circle(-40,70)
    forward(20)
    end_fill()

    color(strColor2)
    begin_fill()
    right(60)
    circle(-300,20)
    right(170)
    circle(300,15)
    right(200)
    circle(-300,20)
    right(170)
    circle(300,25)
    right(200)
    circle(-300,20)
    right(170)
    circle(300,20)
    right(90)
    circle(-200,15)
    end_fill()
    right(95)

intPetals = 10
intAngle = 360/intPetals

for x in range(0,intPetals//2):
    draw_petal("cornflowerblue","lightblue")
    left(intAngle)
    draw_petal("lightblue","yellow")
    left(intAngle)

done()