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

Display codes from different computing languages on WordPress

I came across a post on how to display codes from different languages on WordPress.

Basically, WordPress utilises a feature to turn a piece of, say MATLAB, code from this:

t = 0:dt:10;                       % Time vector
a = 2*sin(2*pi*2*t);            
plot(t,a,'k')			
xlabel('Time [s]')		
ylabel('Signal [-]')

to this:

t = 0:dt:10;                    % Time vector
a = 2*sin(2*pi*2*t);
plot(t,a,'k')
xlabel('Time [s]')
ylabel('Signal [-]')

Putting this way, the syntax will be highlighted, along with the row number.