Learning goals

  • Explain how x0 and y0 set a circle’s center.
  • Explain what the radius parameter controls.
  • Explain how a function draws a filled, centered circle.

This function builds on otto.circle(). It moves to the right start point for you.

What do x0 and y0 tell us?

The point (x0, y0) is the center of the circle. x0 sets the horizontal position of the center. y0 sets the vertical position of the center.

The radius sets the distance from the center to the circle’s edge. The radius parameter gives this distance to the function. The pencolor parameter sets the outline color. The fillcolor parameter sets the inside color. Give the function both colors when you call it.

A blue circle with its center marked by x0 and y0.

How does the function draw?

The turtle starts at the bottom of the circle. That point is (x0, y0 - radius). The turtle faces right, so otto.circle(radius) draws around the center. For example, a radius of 50 makes a circle 100 steps wide and high.

import turtle as otto

def draw_centered_circle(x0, y0, radius, pencolor, fillcolor):
    otto.penup()
    otto.goto(x0, y0 - radius)
    otto.pendown()
    otto.pencolor(pencolor)
    otto.fillcolor(fillcolor)
    otto.begin_fill()
    otto.circle(radius)
    otto.end_fill()

draw_centered_circle(0, 0, 50, "black", "blue")

Animation of Turtle drawing a centered blue circle.

The center is (0, 0), and the radius is 50 steps. The circle is 100 steps wide and high. The outline is black, and the fill is blue.

Summary

Part What it does
x0 Sets the horizontal position of the center.
y0 Sets the vertical position of the center.
radius Sets the distance from the center to the edge.
pencolor Sets the outline color.
fillcolor Sets the inside color.
penup() Moves without drawing a line.
goto(x, y) Moves to a position on the canvas.
pendown() Puts the pen down to draw.
pencolor() Changes the outline color.
fillcolor() Changes the inside color.
begin_fill() Starts filling the circle.
circle() Draws a circle around a center above the turtle.
end_fill() Finishes filling the circle.