We’ve learned a little about loops and about functions. Let’s put them together and have some fun.
The code below has two functions already defined for you: draw_circle and draw_square. See if you can call them in turn to make new pictures. Some ideas are below.
import turtle
tina = turtle.Turtle()
tina.shape("turtle")
def draw_circle(turtle, color, size, x, y):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.begin_fill()
turtle.circle(size)
turtle.end_fill()
turtle.pendown()
def draw_square(turtle, color, size, x, y):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.pendown()
turtle.begin_fill()
turtle.forward(size)
turtle.left(90)
turtle.forward(size)
turtle.left(90)
turtle.forward(size)
turtle.left(90)
turtle.forward(size)
turtle.left(90)
turtle.end_fill()
draw_square(tina, "green", 100, 25, 0)
draw_circle(tina, "blue", 50, 0, 0)
draw_circle(tina, "yellow", 50, -25, 0)
Ideas to try:
draw_circle calls into draw_square calls or vice versa.