Artist

Modern Art

Turtles draw modern art.

Try


Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.

Watch this video to learn about the new concepts shown in the program:

Knowledge Organiser

Command summary

The new commands used in this program and others that may be useful. Select them below to learn more:

turtle.setheading(x)

Sets the orientation of the turtle to x degrees.

turtle.begin_fill()

Starts the process to fill a shape with colour. The shape is only filled once it is fully enclosed and the command turtle.end_fill() has been executed.

turtle.end_fill()

Ends the process of filling a shape once it is complete. Can only be used with turtle.begin_fill().

turtle.circle(x, y)

Draws a circle of radius x. The parameter y is optional but determines the extent of the circle in degrees. turtle.circle(50, 180) would result in half a circle being drawn of radius 50.

turtle.speed(x)

Sets the speed of the turtle to x. The variable can be an integer between 0 and 10 with zero being the fastest. The variable can also be a string: “fastest”, “fast”, “normal”, “slow”, “slowest”.

turtle.hideturtle()

Hides the turtle so it is not shown. Vectors will still be drawn if the pen is down. Graphics are drawn faster if the turtle is not shown.

turtle.showturtle()

Shows the turtle.

turtle.reset()

Clears the drawing canvas, sends the turtle home to 0, 0 and resets turtle properties to default values.

x = turtle.Turtle()

Assigns x to be a new turtle. Note the capital T. You can have as many independent turtles as you need. Storing them in a list is a good way to iterate over them.

turtle.mode(x)

Sets the mode of the turtle to x. The variable can be “standard” or “logo”. A turtle in standard mode, initially points to the right (east) and angles are counter-clockwise. A turtle in logo mode, initially points up (north) and angles are clockwise. This command is not supported in all implementations of the turtle library and should generally be avoided.

w = turtle.Screen()

w is assigned to be the turtle output window. Follow this command with:

w.setup(x, y)

Sets the size of the turtle output window to x pixels width and y pixels height.

turtle.screensize(x, y)

Set the scrollable drawing canvas to x pixels width and y pixels height. Use with turtle.done() to activate scroll bars in some implementations.

Investigate


Questions to think about with this program to check your understanding:

Relation question

What would be the result of swapping lines 13 and 14?

for turtle_number in range(number_of_turtles):

before…

for circles in range(50)

REVEAL ANSWER

Instead of the red and blue circles both being drawn one at a time, all the red circles would be drawn first followed by all the blue circles. That would result in the blue circles always appearing above the red circles when they overlap.

Approach question

Lines 33-36 create a new turtle and its properties. Line 37 adds the new turtle to a list of turtles before looping back to line 32 to start creating a new turtle. Why create a list of turtles when you could instead create and initialise two turtles like this:

red_turtle = turtle.Turtle()

blue_turtle = turtle.Turtle()

REVEAL ANSWER

As we saw in level 6, using lists, indexes and iterators instead of multiple variables with different names makes the program more scalable. You can increase the number of turtles that are drawing by changing line 28 to add more or less turtles and line 29 to add more colours. Changing the scale of the program only requires changing two lines of code.

Taking the alternative approach with multiple variables would mean that you couldn’t use a loop in line 14. Instead you would need to copy the code in lines 15-21 for every turtle resulting in code duplication.

It is a misconception that using lists makes the program faster. It just means the program uses less memory (fewer instructions to store) and easier to change. Arguably it may be easier to debug too because any errors will affect all turtles and not just one.

Make


Success Criteria

Change the program below so that it:

  1. Draws filled hexagons instead of circles.
  2. Create a subprogram: draw_shape(turtle_number) that draws one hexagon.
  3. Replace t[turtle_number].circle(20) in the make_art subprogram with the line: draw_shape(turtle_number)
  4. Has four turtles: red, blue, green and yellow. (You can choose alternative colours if you wish)

Typical inputs and outputs from the program would be:

Due to the random nature of the program, the picture that is drawn will be different each time. To find patterns that are particularly pleasing you could experiment with making the program more deterministic by adding the line random.seed(x) where x is any integer.

Help

Use the flowcharts if you need more support in understanding the steps required to meet the criteria. Use the Parsons code sorting exercise only if you are really stuck.

Flowcharts:
Parsons:

Evaluate


Run your code to check that your program has met the success criteria and produces the required output.

Craig'n'Dave logo

Craig ‘n’ Dave

Bett Awards 2024 Finalist