导语:
哈喽,哈喽~今天小编教大家用python画红旗。
正文:
在这里呢,小编想对所有参加考试的人说:“理想主义的花,最终会盛开在浪漫主义的土壤里,我们的热情永远不会熄灭,在现实的平凡之中,我们终将上岸,阳光万里!”
效果:
代码:
import turtle
import math
def edge(x, y):
turtle.penup()
turtle.goto(x - 144, y + 96) # 起始位置
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('#F40002')
turtle.pen(pencolor='#F40002')
for i in range(2):
turtle.fd(288)
turtle.right(90)
turtle.fd(192)
turtle.right(90)
turtle.end_fill()
def big_star(x, y, len): # x,y为起始坐标,len为五角星边长
turtle.goto(x, y) # 起始位置
turtle.setheading(0) # 倾斜起始角度
turtle.begin_fill()
turtle.fillcolor('#FAF408')
turtle.penup()
turtle.left(18)
turtle.fd(len / 2 / math.cos(18 * math.pi / 180))
turtle.left(162)
turtle.pendown()
turtle.pen(pencolor='#FAF408')
for i in range(5):
turtle.fd(len)
turtle.left(144)
turtle.end_fill()
turtle.penup()
def small_star(x, y, len): # x,y为起始坐标,len为五角星边长
turtle.goto(x, y) # 起始位置
angle = turtle.towards(-10 * 9.8, 5 * 9.8)
turtle.setheading(angle) # 倾斜起始角度 此时小五角星头部对准大五角星中心
turtle.fd(len / 2 / math.cos(18 * math.pi / 180))
turtle.right(162)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('#FAF408')
for i in range(5):
turtle.fd(len)
turtle.right(144)
turtle.end_fill()
turtle.penup()
if __name__ == '__main__':
turtle.setup(width=468, height=312) # 左右两侧留出90像素距离 上下两侧留出60像素距离
turtle.hideturtle()
edge(0, 0)
big_star(-10 * 9.8, 5 * 9.8, 6 * 9.8 * math.cos(18 * math.pi / 180))
small_star(-5 * 9.8, 8 * 9.8, 2 * 9.8 * math.cos(18 * math.pi / 180))
small_star(-3 * 9.8, 6 * 9.8, 2 * 9.8 * math.cos(18 * math.pi / 180))
small_star(-3 * 9.8, 3 * 9.8, 2 * 9.8 * math.cos(18 * math.pi / 180))
small_star(-5 * 9.8, 1 * 9.8, 2 * 9.8 * math.cos(18 * math.pi / 180))
turtle.done()
共产主义社会尚未来到,同志,你的任务尚未完成,你消极学习的样子,像极了反革命!
Onward and upward👊
结尾:
金榜提名,蟾宫折桂!!!
喜欢小编文章的记得给个关注,点击这个蓝色字体也行!