AB: Olympic Rings

T1: Olympic Rings

The following code creates part of the Olympic rings
Adapt the code to create the full Olympic rings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import turtle
import time
wn=turtle.Screen()
b = turtle.Turtle()
b.speed(999999999999999999)
b.pensize(11)
b.color("blue")
b.penup()
b.backward(128)
b.pendown()
b.circle(50)

y = turtle.Turtle()
y.speed(9999999999999999999999999999999999)
y.pensize(11)
y.color("yellow")
y.penup()
y.backward(114)
y.right(90)
y.pendown()
y.circle(50)

The following code adds a background image if you put the image in the same folder as the python script

1
2
3
4
5
import turtle
screen=turtle.Screen()
trtl=turtle.Turtle()
screen.setup(420,320)
screen.bgpic('bg.gif')

Snowflakes

Copy, paste the program into IDLE and run. Adapt the snowflake
If there are some errors in the program the red text will give you a clue and you can correct the errors. This is called Debugging

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import turtle
import random

# setup the window with a background colour
wn = turtle.Screen()
wn.bgcolor("black")
wn.setup(width=250, height=250)

# assign a name to your turtle
turtle = turtle.Turtle()
colors = ["#7D8A2E", "#263248", "#FF8C00", "#F0C600"]

#
def snowflake(size, pensize, x, y):
    """ function that draws a snowflake """
    # turtle.pen(pensize=10)
    turtle.penup()
    turtle.goto(x, y)
    turtle.forward(10*size)
    turtle.left(45)
    turtle.pendown()
    turtle.color(random.choice(colors))

    for i in range(8):
        branch(size)
        turtle.left(45)


# create one branch of the snowflake
def branch(size):
    for i in range(3):
        for i in range(3):
            turtle.forward(10.0*size/3)
            turtle.backward(10.0*size/3)
            turtle.right(45)
        turtle.left(90)
        turtle.backward(10.0*size/3)
        turtle.left(45)
    turtle.right(90)
    turtle.forward(10.0*size)

snowflake(8, 6, 0, 0)

# leave the window open until you click to close
wn.exitonclick()

 

Olympic flags with background


Find a winter Olympic background image (.gif) and code create a program that has the Olympic rings with the background

EXTENSION

Python Turtle Tutorial