Learning Aim
To use variables to store values that control Turtle artwork.
Defined End Point
By the end of this lesson, you will be able to use variables and values to control the size, colour and output of a Turtle artwork.
Creative Code. Colourful Thinking.
Lesson 2
Use variables to control colour, size and movement in Turtle artwork.
Use these stages to move from reading code to creating your own version.
To use variables to store values that control Turtle artwork.
By the end of this lesson, you will be able to use variables and values to control the size, colour and output of a Turtle artwork.
Guess the Variable
size = 50
colour = "blue"
repeats = 12
repeats becomes 24?Stretch: Write your own variable.
Read the code and predict what will change if the value of size changes.
Read the code first. Do not run it yet.
from turtle import *
size = 80
pencolor("purple")
circle(size)
What do you think the variable size controls?
Watch how variables are used to control the Turtle output before typing the code yourself.
Type this code into Mu Editor and run it.
from turtle import *
size = 80
colour = "purple"
thickness = 4
pencolor(colour)
pensize(thickness)
circle(size)
right(90)
circle(size)
Typing the code yourself helps build Python fluency and debugging skills.
Find the lines that store values and connect them to the artwork.
Which line controls the circle size?
Which line controls the pen colour?
Which line controls the pen thickness?
Change one variable at a time and test the output after each change.
Create a simple interactive artwork by choosing variables for colour, size and pen thickness.
Change the colour and size variables.
Add a second shape using the same variables.
Create a pattern using at least three variables.
Example code and output.
Use the example to connect the Python instructions with the visual result.
Example code
from turtle import *
size = 80
colour = "purple"
thickness = 4
pencolor(colour)
pensize(thickness)
circle(size)
right(90)
circle(size)
This WAGOLL uses named variables so the design can be changed without rewriting every command.
Explain what you learned and identify the next improvement you would make.
Add a variable called turn_angle and use it to rotate your artwork.
Why is it useful to store values in variables?