Python3 turtle 国旗绘制
WARNING:低技术力
自己无聊写的
使用turtle库
进入程序后,按下1绘制中华人民共和国国旗,按下2绘制朝鲜民主主义人民共和国国旗,按下0退出程序。
温馨提示:在绘制完成前不要输入下一个命令,否则会卡死。
效果图:
中华人民共和国国旗↓
朝鲜民主主义人民共和国国旗↓
程序代码:
#!usr/bin/env python3
# -*- coding:UTF-8 -*-
import turtle as t
import sys
t.hideturtle()#X隐藏海龟
t.speed(10)#海龟速度
def qm(h,l):#旗面绘制函数:h高,l宽
t.pendown()
t.begin_fill()
for i in range(0,4):
if (i%2)==0:
t.forward(l)
else:
t.forward(h)
t.right(90)
t.end_fill()
t.penup()
def star5(f):#五角星绘制函数:f边长
t.left(18)
t.pendown()
t.begin_fill()
for a in range(0,5):
t.forward(f)
t.right(144)
t.end_fill()
t.penup()
def PRC():#中华人民共和国国旗
t.setheading(0)#角度初始化
t.clear()
h=1000#长宽关系
l=h*1.5
t.penup()
t.color("red")
t.goto(int(-l/2),int(h/2))#位置初始化
qm(h,l)#旗面绘制
t.color("yellow")
#大五角星
t.goto(int(-l/6*2),int(h/2*4/5))
t.setheading(0)
t.right(90)
star5(286)
x,y=int(-l/2*2/3),int(h/4)
def Xiaowujaioxing(left,forward):
nonlocal x
nonlocal y
t.goto(x,y)
t.setheading(0)
t.left(left)
t.forward(forward)
star5(95)
Xiaowujaioxing(31,242)
Xiaowujaioxing(8,304)
Xiaowujaioxing(-16,314)
Xiaowujaioxing(-39,270)
#END
def DPRK():#朝鲜民主主义人民共和国国旗
t.setheading(0)#角度初始化
t.clear()
h=720
l=h*2
t.penup()
t.color("red")
t.goto(int(-l/2),int(h/2))#位置初始化
qm(h,l)
x,y=-l/2/3,0
t.goto(x,y-h*16/36/2)
#五星外环圆
t.color("white")
t.pendown()
t.begin_fill()
cr=int(h*32/72/2)
t.circle(cr,360)
t.end_fill()
t.penup()
t.color("red")
star_cr=cr//100
#五星位置
t.goto(x,y+h*16/36/2-star_cr*3)
#五星
t.setheading(0)
t.right(90)
star5(298)
#蓝色
t.color("blue")
t.setheading(0)
t.goto(int(-l/2),int(h/2))#位置初始化
qm(h/2*0.3,l)
t.goto(int(-l/2),int(-h/2+h/2*0.3))#位置初始化
qm(h/2*0.3,l)
#白色
t.color("white")
t.setheading(0)
t.goto(int(-l/2),int(h/2-h/2*0.3))#位置初始化
qm(h/2*1/18,l)
t.goto(int(-l/2),int(-h/2+h/2*0.3+h/2*1/18))#位置初始化
qm(h/2*1/18,l)
def main():
c=input()
d={'0':'sys.exit()','1':'PRC()','2':'DPRK()'}
eval(d[c])
main()
main()
END
Bilibili@GALACTIC国家机器
本人B站主页欢迎访问