In this activity, we will be creating a “Rainbow Spiral” with the Python programming language and using the Turtle Library.

We will create a program that will draw lines of increasing width around a central point making an attractive pattern.

Taken and adpated from: Geeks for Geeks: Turtle Programming in Python - no4. Rainbow Benzene

1 - Setup

Go to trinkiet.io and start a new Python project: http://bit.ly/pythontrinket (log into your account if you have one or create one to save your progress). Then:

Import the turtle module into your project

import turtle 

Initialize Turtle() as t:

t = turtle.Turtle()

Initialize Screen() as s:

s = turtle.Screen()

Set the screen background colour to black:

s.bgcolor('black')

Set turtle speed to fastest:

t.speed('fastest')

2 - The for loop

Write a for loop for a range of 200:

for x in range(200):

Inside the loop (remember it needs to be indented!) set the pen colour:

t.pencolor('blue')

Still inside the loop set the line width to get wider each loop:

t.width(x/100 + 1)

Still inside the loop move the turtle forward to draw a line:

t.forward(x)

Finally, still in the loop, lets change the angle of the turtle to create the spiral:

t.left(79)

3 - Run the program!

You should be able to now run the program. You should get something that looks like this: A blue spiral

4 - Challenges

5 - Challenge Solutions