Log in to save your progress.
<< Previous
Home
Next >>
Note! The window is too narrow to use Pythonlab.dev. Use a device with a keyboard!

Reference

Click on a function to read more.
Turtle
Function
Short description
back()
Moves the turtle backward
begin_fill()
Starts filling with color
circle()
Draws a circle with optional radius
color()
Determines the color the turtle draws with
end_fill()
Ends filling with color
forward()
Moves the turtle forward
goto()
Moves the turtle to a given coordinate
hideturtle()
Hides the turtle
left()
Turns the turtle left a number of degrees
pendown()
Puts the pen down on the drawing area.
penup()
Lifts the pen from the drawing area
right()
Turns the turtle right a number of degrees
shape()
Changes the drawing shape
Screen().setup()
Creates a drawing area with a given size
speed()
Sets the turtle's drawing speed

Drawing circles

Here you will learn to

Draw a circle

To draw a circle, use circle(radius) where the argument radius is a number that specifies how large the radius of the circle should be.

Example

Draw a circle with a radius of 50.

circle(50)

Now we will try to draw several circles with different radii.

Example

Three circles with different radii

circle(25)
circle(50)
circle(75)
  

Write hideturtle() to hide the turtle when the code is finished.

Example

Another example with three circles. The turtle is hidden at the end.

circle(50)
right(120)
circle(50)
right(120)
circle(50)

hideturtle()
  

Login or create an account to save your progress and your code.

What does the code do?

Read the code below and try to figure out what the program draws. Run the program after you answer and see if you were correct.

Question: What will the program draw?

A square inside a circle
A circle inside a square
A circle and a square with equal areas

You can tell the turtle to only draw part of a circle. This is done by using two arguments for the circle() function. The first argument is, as before, the radius, while the second argument is the angle, where 360 degrees is a full circle. The arguments are separated by , (a comma). See the example below.

Example

Draw a part of a circle. Try changing the value of the second argument!

circle(50, 180) #half circle
circle(50, 90) #quarter circle
  

Picking up and putting down the pen

Pick up the pen with penup(). Then the turtle moves without drawing. Use pendown() to put the pen down again.

Example

Draw two circles in two different places with the help of penup() and pendown().

Feel free to try commenting out (put # in front of) penup() and see what it looks like.

penup()
back(100)
pendown()
circle(50)
penup()
forward(200)
pendown()
circle(50)
  

Login to save your progress and your code.

Modify the code

Use penup() and pendown() for the turtle to draw a happy smiley. The turtle should not draw while it moves between different parts.

Filling figures with color

So far we have only been able to draw lines. To fill in figures we have drawn, begin_fill() and end_fill() are used. Write begin_fill() first on a line before you draw and then end_fill() on a line after the figure to be colored is finished. The color can be chosen with color(color) just like for lines.

Example

Draw a colored circle.

color('green')
    
begin_fill()
circle(75)
end_fill()
  

Login or create an account to save your progress and your code.

What does the code do?

Read the code below and try to figure out what the program draws. Run the program after you answer and see if you were correct.

Question: What will the program draw?

A star with five points
Two triangles next to each other
A pentagon without crossing lines

Login to save your progress and your code.

Modify the code

Use begin_fill() and end_fill() to fill the figure with any color.

After these first two sections, we have gone through the basics of the turtle module. In the next section, we will move on to more general programming concepts.

Status
You have finished all tasks in this section!
🎉