Turtle
The turtle
module is designed for creating drawings and serves as a tool for learning how to code.
from turtle import *
forward(100) # moving forward the given number of pixels (also: fd())
right(90) # turning right by 90 degrees
backward(100) # moving backward the given number of pixels (also: bk() or back())
left(90) # turning left by 90 degrees
circle(100) # drawing a circle
undo() # undoing the last action
for x in range(4):
left(90)
dot(20) # placing a dot
penup() # lifting the pen up
forward(100)
pendown() # lowering the pen down
speed(3) # setting the drawing speed (fastest: 0, fast: 10, normal: 6, slow: 3, slowest: 1)
shape("turtle") # setting the turtle's shape (arrow, turtle, circle, square, triangle, and classic)
for x in range(4):
penup()
forward(120)
pendown()
stamp() # placing a stamp that looks like that the turtle's shape
if x < 2:
left(90)
else:
right(90)
goto(0, 0) # moving to the specified coordinates
forward(100)
print(position()) # retrieving the current coordinates
pencolor("red") # changing the pen color
forward(100)
fillcolor("red") # setting the fill color
begin_fill() # starting the filling procedure
for x in range(4):
forward(100)
right(90)
end_fill() # ending the filling procedure
home() # moving to the (0, 0) coordinates