Category Archives: Python

Draw Vietnamese flag using Turtle module in Python

Using the module turtle and Python3. The following program will generate (roughly) the Vietnamese flag.

import turtle
wn = turtle.Screen()            # Set up the window and its attributes
wn.bgcolor("red")               # Background color of the screen
screen_width = 750;             # Width of the screen
screen_height = 500;            # Height of the screen
star_length = 200;              # Length of one side of the star

wn.setup(width = screen_width, height = screen_height)
wn.title("Flag of Vietnam")

vin = turtle.Turtle()
vin.color("red")                # Set the color of the turtle to red
# Move the turtle to a predefined coordinate
vin.setx((screen_width - star_length)/2 - screen_width/2)
vin.sety(star_length/4)
vin.color("yellow")
vin.shape("blank")              # Hide the shape of the turtle
vin.pensize(3)                  # Pen size of the turtle

# Draw the flag
for counter in range(5):
    vin.forward(star_length)                 
    vin.right(144)

wn.exitonclick()

and the result is:

vietnamese_flag

Advertisements