Python3 turtle 国旗绘制 (4)

tech2026-03-06  7

Python3 turtle 国旗绘制 WARNING:低技术力 自己无聊写的 使用turtle库 进入程序后,按下6绘制俄罗斯联邦国旗,按下7绘制法兰西第五共和国国旗,按下8绘制土耳其共和国国旗,按下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 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 RUF():#俄罗斯联邦国旗 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)#旗面绘制 t.goto(int(-l/2),int(h/6)) t.color("darkblue") qm(h/3,l) t.goto(int(-l/2),int(-h/6)) t.color("red") qm(h/3,l) def FRR():#法兰西第五共和国国旗 t.setheading(0)#角度初始化 t.clear() h=1000#长宽关系 l=h*1.5 t.penup() qml(h,l)#边界 t.color('red') t.goto(int(-l/2),int(h/2))#位置初始化 qm(h,l)#旗面绘制 t.color('blue') t.goto(int(-l/2),int(h/2)) qm(h,l/3) t.color('white') t.goto(int(-l/2+l/3),int(h/2)) qm(h,l/3) def ROT(): t.setheading(0)#角度初始化 t.clear() h=1000#长宽关系 l=h*1.5 t.penup() qml(h,l)#边界 t.color('red') t.goto(int(-l/2),int(h/2))#位置初始化 qm(h,l)#旗面绘制 #星月 t.color('white')#月 t.goto(int(-l/2+h/2),int(-h/4)) t.pendown() t.setheading(0) t.begin_fill() t.circle(h/4,360) t.end_fill() t.penup() t.color('red')#月 t.goto(int(-l/2+h/2+h/16),int(-h*2/5/2)) t.pendown() t.setheading(0) t.begin_fill() t.circle(h*2/5/2,360) t.end_fill() t.penup() t.color('white')#星 t.goto(int(-l/2+h/2+h/16-h/3/2+h/3),0) t.setheading(0) star5(h/4*1.05) def main(): c=int(input()) d={0:'sys.exit()'6:'RUF()', 7:'FRR()',8:'ROT()'} eval(d[c]) main() main()
最新回复(0)