Python3 turtle 国旗绘制 (3)

tech2022-09-04  111

Python3 turtle 国旗绘制 WARNING:低技术力 自己无聊写的 使用turtle库 进入程序后,按下3绘制大韩民国国旗,按下4绘制日本国国旗,按下0退出程序。 温馨提示:在绘制完成前不要输入下一个命令,否则会卡死。

#!usr/bin/env python3 # -*- coding:UTF-8 -*- import turtle as t import sys t.hideturtle()#X隐藏海龟 t.speed(10)#海龟速度 def qml(h,l):#边界 t.goto(int(-l/2)-1,int(h/2)+1)#位置初始化 t.color('black') t.pendown() for i in range(0,4): if (i%2)==0: t.forward(l+2) else: t.forward(h+2) t.right(90) t.penup() 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 ROK():#大韩民国国旗 t.setheading(0)#角度初始化 t.clear() h=800#长宽关系 l=h*3/2 t.penup() qml(h,l)#边界 t.color('white') t.goto(int(-l/2),int(h/2))#位置初始化 qm(h,l)#旗面绘制 t.goto(0,0-h/2) ap=34 r=h/4 def taiji(x,y,r,c1,c2):#太极 nonlocal h nonlocal ap t.goto(x,y)#复位 t.setheading(180-34) t.color(c1) t.forward(r) t.setheading(180-34+90) t.pendown() t.begin_fill() t.circle(r,180) t.end_fill() t.color(c2) t.begin_fill() t.circle(r,180) t.circle(r/2,180) t.end_fill() t.setheading(-34) t.pendown() t.forward(r) t.color(c1) t.begin_fill() t.setheading(-34+90) t.circle(r/2,180) t.end_fill() t.penup() taiji(0,0,r,'darkblue','red') def bagua():#八卦 nonlocal r nonlocal ap d=r*2 h=d/12 l=r t.color('black') def weizhi():#到达八卦的起始位置 t.forward(d/4+d/24*2+d/12*3+d/2) t.left(90) t.forward(l/2) t.right(180) def chang():#长 nonlocal d nonlocal l qm(h,l) def duan():#短 nonlocal d nonlocal l qm(h,l/2-d/2/24) t.forward(l/2-d/2/24+d/24) qm(h,l/2-d/2/48) #t.right(180) t.forward(-l/2-d/2/24) def baguaq(a,b,c): weizhi() e=[a,b,c] for f in e: if f==1: chang() else: duan() t.right(90) t.forward(h+d/24) t.left(90) t.goto(0,0) t.setheading(180-ap) baguaq(1,1,1)#乾 t.setheading(ap) baguaq(0,1,0)#坎 t.setheading(-ap) baguaq(0,0,0)#坤 t.setheading(180+ap) baguaq(1,0,1)#离 bagua() def JP():#日本国国旗 t.setheading(0)#角度初始化 t.clear() h=1000#长宽关系 l=h*1.5 t.penup() qml(h,l)#边界 t.color('white') t.goto(int(-l/2),int(h/2))#位置初始化 qm(h,l)#旗面绘制 r=h*3/5/2 t.pendown() t.goto(0,0-r) t.color('red') t.begin_fill() t.circle(r,360) t.penup() t.end_fill() def main(): c=int(input()) d={0:'sys.exit()',1:'PRC()',2:'DPRK()', 3:'USA()',4:'ROK()',5:'JP()'} eval(d[c]) main() main()

END Bilibili@GALACTIC国家机器 本人B站主页欢迎访问

最新回复(0)