编程语言
首页 > 编程语言> > Python 画五星红旗

Python 画五星红旗

作者:互联网

# -*- coding: UTF-8 -*-
# Created by cdh at 2020/4/20
# Red flag
import turtle
turtle.speed(100)

# background Red
turtle.pu()
turtle.goto(-300, -200)
turtle.pd()
turtle.color('red')
turtle.begin_fill()
for i in range(2):
    turtle.fd(600)
    turtle.left(90)
    turtle.fd(400)
    turtle.left(90)
turtle.end_fill()

# 大小星星的外接圆直径
len_star_big = 400 * 3 / 10
len_star_small = 400 * 1 / 10

# 设置星星的颜色,画出大星星
turtle.color("yellow")
turtle.pu()
turtle.goto(-250, 110)
turtle.pd()
turtle.begin_fill()
for i in range(5):
    turtle.forward(len_star_big)
    turtle.right(144)
turtle.end_fill()

angle = 36
# 画小星星
for i in range(4):
    # 回到大星星的中心
    turtle.pu()
    turtle.goto(-190, 90)
    turtle.setheading(0)

# 到小星星起笔位置,并调整起笔角度
    turtle.left(36-24 * i)
    turtle.fd(120)
    turtle.left(angle / 2)

# 开始画小星星
    turtle.begin_fill()
    for j in range(5):
        turtle.forward(len_star_small)
        turtle.right(144)
    turtle.end_fill()

turtle.pu()
turtle.goto(-80, 220)
turtle.color("red")
turtle.write("National flag", font=('Arial', 20, 'normal'))
turtle.pu()
turtle.goto(0, 0)

# 画板保留
turtle.exitonclick()

五星红旗

标签:turtle,star,goto,pu,Python,len,五星红旗,fill
来源: https://blog.csdn.net/qq_43492938/article/details/105645162