Learn > BGE > Python – Turtle Graphics > 4. Variables >
Flags
Task 1 - France
Write a program that will draw the French flag.
Algorithm
- Draw blue rectangle (100 x 200)
- Forward 100
- Draw white rectangle (100 x 200)
- Forward 100
- Draw red rectangle (100 x 200)
Code
from turtle import *
screen = getscreen()
tom = Turtle()
RectWidth = 100
rectHeight = 200
angle = 90
# BLUE STRIPE
tom.fillcolor("blue")
tom.begin_fill()
for counter in range(2):
tom.forward(RectWidth)
tom.right(angle)
tom.forward(rectHeight)
tom.right(angle)
tom.end_fill()
# MOVE TO NEXT STRIPE
tom.forward(RectWidth)
# WHITE STRIPE
tom.fillcolor("white")
tom.begin_fill()
for counter in range(2):
tom.forward(RectWidth)
tom.right(angle)
tom.forward(rectHeight)
tom.right(angle)
tom.end_fill()
# MOVE TO NEXT STRIPE
tom.forward(RectWidth)
# RED STRIPE
tom.fillcolor("red")
tom.begin_fill()
for counter in range(2):
tom.forward(RectWidth)
tom.right(angle)
tom.forward(rectHeight)
tom.right(angle)
tom.end_fill()
Task 2 - Germany
Write a program that will draw the German flag.
Algorithm
- Draw black rectangle
- Move down
- Draw red rectangle
- Move down
- Draw yellow rectangle
Code
from turtle import *
screen = getscreen()
tom = Turtle()
width = 450
height = 100
angle = 90
tom.fillcolor("black")
tom.beginfill()
for counter in range(4):
tom.forward(width)
tom.right(angle)
tom.forward(height)
tom.right(angle)
tom.endfill()
# Draw red rectangle
# Draw yellow rectangle
Task 4 - Scotland
Write a program that will draw the Scottish flag.