Using Colour in Turtle

We can add colour to our Turtle graphics by altering the line colour and the fill colour.

Pen Colour

We can change the line colour that gets drawn in turtle with the following line.

turtle.pencolor(“Red”)

The above code would make any lines drawn after be coloured red. We can change the line colour as many times as we like in our programs Please note the americanised spelling!

import turtle

turtle.pencolor(“Green”)

turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)

The above code created a square with a green pen colour.

Fill Colour

We can also fill the shapes we draw with colour. Firstly we use this line of code to state which colour to fill shapes with:

turtle.fillcolor(“Red”)

After this we need to tell python when to begin the fill and when to end it.

turtle.begin_fill()

turtle.end_fill()

It will not work unless we end the fill and the lines of shape fully join up.


Included in the following specifications:
KS3 Computing