## Python turtle drawing - drawing the national flag

osc_ p5er4r6g 2020-11-13 12:41:02
python turtle drawing drawing national

Be sure to know the specifications before drawing , I found a rough picture .

Refer to the picture ：

The way to draw a big star is very simple , The complement of the pentagram is 144 degree .

It's a bit of a hassle to draw a pentagram , Because the small five pointed star on our national flag is not flat （ The United States once missed our flag like this ）, But there is always an angle facing the center of the big five pointed star ！ My approach is , Locate the center of the little Pentagram , And then back a certain length according to the angle . This angle can be calculated from the anti Pythagorean theorem （ There are Calculation tools ）, I divide the length by the distance from the center of the big Pentagram to the tip of the corner 3 Got .

Code ：

``````from turtle import *
screensize(2000,2000,'white')# Set canvas size
# Draw flag face
pencolor('red')
pu()
goto(-300,-200)
pd()
fillcolor('red')
begin_fill()
for i in range(0,2):
fd(600)
lt(90)
fd(400)
lt(90)
end_fill()
# Draw the big five pointed star
pu()
pencolor('yellow')
goto(-260,120)
pd()
fillcolor('yellow')
begin_fill()
for i in range(0,5):
fd(120)
rt(144)
end_fill()
# Draw four little pentagrams
list1 = [(-100,160),(-60,120),(-60,60),(-100,20)]# The central coordinates of the four pentagonal stars
list2 = [31.98,8.13,-15.59,-38.66]# Relative angle 0 The retreat of 1.111 You need to turn left
for j in range(0,4):
seth(0)# This is the glans. The angle is 0
pu()
goto(list1[j])# Locate the center of the pentagram
lt(list2[j])# Rotation Angle , Pointing back to the tip of the big Pentagram
bk(1.111)# From the center of the pentagram to the point of the big five pointed star （ The tortoise crawled backwards ）
lt(18)# Half angle of Pentagram
pd()
fillcolor('yellow')
begin_fill()
for i in range(0, 5):
fd(40)
rt(144)
end_fill()