Python draws the national flag

Article directory


foreword

Today, let's use the turtle library to draw the national flag


1. American flag

, the shape of the national flag is rectangular; the ratio of length to width of the national flag is 19:10, and the American flag is composed of red, white and blue; the picture pattern is composed of two parts, and 50 white The stars are arranged in a row of 6 and a row of 5, a total of 9 rows; the rest of the flag is 13 red and white stripes, with 7 red horizontal stripes and 6 white horizontal stripes.

import  turtle    
t = turtle.Pen()
b = turtle.Pen()   
t.speed(800)      
def ct(c):    
    t.color(c)     
    t.begin_fill()
    for i in range(2):
        t.forward(247)  
        t.right(90)
        t.forward(10)
        t.right(90)
    t.end_fill()
for i in range(14):  
    if i%2==1:   
        c ='white'
    else:
        c ='red'
    ct(c)
    t.right(90)
    t.forward(10)
    t.left(90)
t.up()     
t.home()
t.down()
for j in range(4):   
    t.color('blue')    
    t.begin_fill()
    t.forward(120)
    t.right(90)
    t.forward(70)
    t.right(90)
    t.end_fill()
def wjx():       
    b.color('white')
    b.begin_fill()
    for g in range(5):
        b.forward(6)
        b.left(144)
    b.end_fill()
def wjx6():     
    for l in range(6):
        b.up()
        b.forward(3)
        b.down()
        wjx()
        b.up()
        b.forward(18)
        b.down()
def wjx5():     
    for l in range(5):
        b.up()
        b.forward(10)
        b.down()
        wjx()
        b.up()
        b.forward(13)
        b.down()
b.right(90)    
b.forward(7)      
b.left(90)
for u in range(9):      
    if u%2 == 0:        
        wjx6()
    else:
        wjx5()     
    b.up()     
    b.home()
    b.right(90)
    b.forward((u+2)*7)
    b.left(90)
    b.down()
turtle.done()   

 

 

2. Flag of Åland Islands

 Åland Islands, also known as Ahvenanmaa (Ahvenanmaa), is the only autonomous province in Finland. It is located on the southwestern coast of Finland. The capital of Åland is Mairenhamn.

import turtle

width = 900
height = 600

turtle.screensize(width,height,"#0053a5")
turtle.setup(width,height)
t = turtle.Turtle()
t.speed(10)

t.pencolor("#ffce00")
t.fillcolor("#ffce00")
t.hideturtle()

t.penup()
t.goto(0,-170/3)
t.pendown()
t.begin_fill()
t.forward(width / 2)
t.left(90)
t.forward(170)
t.left(90)
t.forward(width)
t.left(90)
t.forward(170)
t.end_fill()

t.penup()
t.goto(0,height/2)
t.pendown()
t.begin_fill()
t.forward(height)
t.right(90)
t.forward(170)
t.right(90)
t.forward(height)
t.end_fill()

t.pencolor("#d21034")
t.fillcolor("#d21034")

t.penup()
t.goto(-170 / 3,height/2)
t.pendown()
t.begin_fill()
t.left(90)
t.forward(170/3)
t.left(90)
t.forward(height)
t.left(90)
t.forward(170/3)
t.end_fill()

t.penup()
t.goto(-width/2,0)
t.pendown()
t.begin_fill()
t.forward(width)
t.left(90)
t.forward(170/3)
t.left(90)
t.forward(width)
t.left(90)
t.end_fill()

turtle.mainloop()

 

 


Summarize

That's it for today, goodbye~~

Guess you like

Origin blog.csdn.net/we123aaa4567/article/details/130348133