Here you will learn to
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.
Draw a circle with a radius of 50.
circle(50)
Now we will try to draw several circles with different radii.
Three circles with different radii
circle(25)
circle(50)
circle(75)
Write hideturtle() to hide the turtle when the code is finished.
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.
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.
-- Output from your program will be here --
Question: What will the program draw?
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.
Draw a part of a circle. Try changing the value of the second argument!
circle(50, 180) #half circle
circle(50, 90) #quarter circle
Pick up the pen with penup(). Then the turtle moves without drawing. Use pendown() to put the pen down again.
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.
Use penup() and pendown() for the turtle to draw a happy smiley. The turtle should not draw while it moves between different parts.
-- Output from your program will be here --
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.
Draw a colored circle.
color('green')
begin_fill()
circle(75)
end_fill()
Login or create an account to save your progress and your code.
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.
-- Output from your program will be here --
Question: What will the program draw?
Login to save your progress and your code.
Use begin_fill() and end_fill() to fill the figure with any color.
-- Output from your program will be here --
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.