庆祝国庆-五星红旗 python海龟作图
祝祖国越来越繁荣富强,国泰民安!
1. 源代码如下
from turtle import *l = 960d = l * 2 / 3n = 1x = l / 30y = d / 20s = 5class Five_Star_Red_Flag:def __init__(self):global l, dsetup(1100, 700, 240, 50)screensize(l, d) # 240:160speed(s)def rectangle(self):pu()forward(l/2)right(90)pd()global nwhile n <= 2:forward(d/2)right(90)forward(l)right(90)forward(d/2)n += 1pu()home()def line(self):goto(l/2, 0)right(180)pd()forward(l)pu()goto(0, d/2)left(90)pd()forward(d)pu()def stars_line_x(self):goto(0, 0)global nn = 1pd()while n <= 7:right(90)forward(l/30)right(90)forward(d/2)left(90)forward(l/30)left(90)forward(d/2)n += 1pu()def stars_line_y(self):goto(0, 0)right(180)global npd()while n <= 11:forward(d/20)left(90)forward(l/2)right(90)forward(d/20)right(90)forward(l/2)left(90)n += 1forward(d / 20)left(90)forward(l / 2)pu()home()def stars(self, xx, yy, r, angle):global n, x, yr = y * ra = xx * xc = yy * yn = 1b = (r * 0.73)goto(a, c)left(angle)forward(r)pd()begin_fill()while n <= 5:right(162)forward(b)left(72)forward(b)left(18)n += 1end_fill()pu()home()def draw():# 为了方便绘制做的线draw = Five_Star_Red_Flag()color("white", "white")draw.line()# 方便画图做的线draw.stars_line_x()draw.stars_line_y()end_fill()def main():main = Five_Star_Red_Flag()color("red", "red")begin_fill()main.rectangle()end_fill()# draw() # 为了方便绘制color("yellow", "yellow")main.stars(-10, 5, 3, 90)main.stars(-5, 8, 1, 120.95) # (-5, 8 坐标 1 半径 120.95 面向大star中心的角度)main.stars(-3, 6, 1, 188.1344)main.stars(-3, 3, 1, 164.046)main.stars(-5, 1, 1, 141.3206)hideturtle()done()if __name__ == '__main__':main()
2. 作图视频
庆祝国庆-五星红旗 python海龟作图
3. 作图细节
庆祝国庆-五星红旗 python海龟作图(细节)
最后祝祖国越来越繁荣富强,国泰民安!