欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python-五行红旗实现

程序员文章站 2022-11-14 08:42:17
import turtle""" 绘制五星红旗 作者:zxj 版本:1.0"""# 绘制矩形函数def giant(leg,hig): turtle.fillcolor("red") turtle.begin_fill() for x in range(1, 5): if x % 2 == 1: n... ......
import turtle
"""
绘制五星红旗
作者:zxj
版本:1.0
"""


# 绘制矩形函数
def giant(leg,hig):
turtle.fillcolor("red")
turtle.begin_fill()
for x in range(1, 5):
if x % 2 == 1:
n = leg
else:
n = hig
turtle.forward(n)
turtle.right(90)
turtle.end_fill()
#绘制五角星函数
def star(leg):
turtle.fillcolor("yellow")
turtle.begin_fill()
for x in range(1, 5):
turtle.forward(leg)
turtle.right(144)
turtle.end_fill()

def main():
turtle.penup()
turtle.backward(200)
turtle.pendown()
#调用绘制矩形函数传入长和宽
giant(288,192)
turtle.penup()
turtle.right(-90)
turtle.backward(40)
turtle.right(90)
turtle.penup()
turtle.forward(25)
#turtle.forward(20)
#调用绘制五角星函数传入长
#大五角星
star(50)
#四个小五角星
turtle.penup()
turtle.right(130)
turtle.backward(20)
turtle.right(30)
turtle.penup()
turtle.forward(40)
star(15)

turtle.penup()
turtle.right(10)
turtle.backward(20)
turtle.right(40)
turtle.penup()
turtle.forward(40)
star(15)

turtle.penup()
turtle.right(30)
turtle.backward(40)
turtle.right(30)
turtle.penup()
turtle.forward(40)
star(15)

turtle.penup()
turtle.right(90)
turtle.backward(35)
turtle.right(30)
turtle.penup()
turtle.forward(35)
star(15)
turtle.hideturtle()
turtle.exitonclick()

if __name__=='__main__':
main()

python-五行红旗实现