Python Turtle is a good way to learn basic programming syntax of Python. You can use it to teach programming to kids. It is like a canvas or easel board that enables you to draw different figures by giving commands to turtle.
import turtle or from turtle import *
t = turtle.Turtle()
turtle.done()
Methods | Description |
---|---|
Turtle() | Creates a turtle object. |
forward(distance) | This method moves the turtle forward by a specified distance. |
backward(distance) | This method moves the turtle backward by a specified distance. |
left(angle) | It is used to turn the turtle anti-clockwise by a specified angle. |
right(angle) | It is used to turn the turtle clockwise by a specified angle. |
goto(x, y) | It moves the turtle to the position (x,y) on the canvas. |
dot(size) | This method draws a dot of a specified size. |
circle(radius) | It draws a circle of a provided radius. |
stamp() | Leaves a mark of turtle shape at the current position. |
shape('shapename') | Changes the shape of a turtle to the specified shape. You can pass arrow, square, triangle, circle, and turtle. |
setheading(angle) | It is used to set the orientation of the turtle to the provided angle. |
penup() or up() | It lifts up the turtle's pen and no drawing after calling this method. |
pendown() or down() | It puts the turtle's pen on the canvas and drawing can be done after calling this method. |
color('colorname') or color('#rrggbb') | Sets the fill color and color of the turtle's pen. |
pencolor('colorname') or pencolor('#rrggbb') | Sets a color of the turtle's pen. |
fillcolor('colorname') or fillcolor('#rrggbb') | Sets the fill color of the turtle that will fill a polygon. |
begin_fill() | When you want to fill a shape with a color, then call this method. This method will remember the initial position of a filled polygon. |
end_fill() | This method fills the polygon with the current fill color by closing it between the current position and the initial position. |
write('text') | Writes a text on the canvas. |
Using above methods, you can draw numerous shapes and figures. Even you can draw using different colors and fill shapes with your favorite color.