Turtle Time
Learn how to draw shapes in python with this free python web tutorial.
STEP 1
Run the following code:
Run the following code:
The above code will create a square using the the turtle library in Python.
Let's explore the code:
STEP 2
Below are the basic commands for drawing shapes in Python:
Using the sample code (above) draw each of the following shapes:
Let's explore the code:
- import turtle (Imports the turtle library)
- window = turtle.Screen() (Creates a new blank canvas to draw on)
- timmy = turtle.Turtle() (Creates a new turtle called timmy)
- timmy.forward(100) (Move the turtle forwad 100 steps)
- timmy.right(90) (Rotates the turtle right by 90 degrees)
- timmy.forward(100) (Move the turtle forwad 100 steps)
- timmy.right(90) (Rotates the turtle right by 90 degrees)
- timmy.forward(100) (Move the turtle forwad 100 steps)
- timmy.right(90) (Rotates the turtle right by 90 degrees)
- timmy.forward(100) (Move the turtle forwad 100 steps)
- timmy.right(90) (Rotates the turtle right by 90 degrees)
STEP 2
Below are the basic commands for drawing shapes in Python:
- forward (Move the turtle forward)
- backward (Move the turtle backwards)
- right (Right turn)
- left (Left turn)
- penup (Pen up)
- pendown (Pen down)
- pensize (Change the size of the pen)
- pencolor (Change the pen colour)
Using the sample code (above) draw each of the following shapes:
Help
angles_worksheet.pdf |
Use the code window above to test your code for each shape.
Bonus Challenge
Finished? Try to draw the following shape:
Finished? Try to draw the following shape:
STEP 3
Can you identify the repeating pattern in the first example (shown above)?
Answer: The instructions forward(100) + right(90) are repeated 4 times!
We can optimise our code by ‘using a loop’. For example.
Can you identify the repeating pattern in the first example (shown above)?
Answer: The instructions forward(100) + right(90) are repeated 4 times!
We can optimise our code by ‘using a loop’. For example.
Optimised code for creating a square
Final challenge
Optimise each of your solutions for each of the shapes (above) by using loops.
Optimise each of your solutions for each of the shapes (above) by using loops.
You may also be interested in:
Tags: Python web, python programming language, python programming, python coding, turtle, python turtle