Ⅰ 急求!這是一個用python畫國旗的程序,請求大神解釋一下每一步是幹嘛的
import turtle //導入模塊
import time
import os
def draw_square(org_x, org_y, x, y): //定義紅旗繪制函數
turtle.setpos(org_x, org_y) //定義畫筆初始位置
turtle.color('red', 'red') //顏色
turtle.begin_fill() //開始繪制
turtle.fd(x) //繪制偏轉方向和角度
turtle.lt(90)
turtle.fd(y)
turtle.lt(90)
turtle.fd(x)
turtle.lt(90)
turtle.fd(y)
turtle.end_fill() //繪制結束
def draw_star(center_x, center_y, radius): //定義星星繪制函數
print(center_x, center_y) //顯示位置
turtle.pencolor('black') //畫筆軌跡顏色
turtle.setpos(center_x, center_y) //中心點位置
pt1 = turtle.pos() //偏轉角度計算
turtle.circle(-radius, 360 / 5)
pt2 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt3 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt4 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt5 = turtle.pos()
turtle.color('yellow', 'yellow') //星星顏色
turtle.begin_fill() //開是繪制
turtle.goto(pt3)
turtle.goto(pt1)
turtle.goto(pt4)
turtle.goto(pt2)
turtle.goto(pt5)
turtle.end_fill() //繪制結束
print(turtle.pos())
turtle.pu() //隱藏畫筆軌跡
draw_square(-320, -260, 660, 440) //繪制紅旗
star_part_x = -320 //自定義星星大小等屬性
star_part_y = -260 + 440
star_part_s = 660 / 30
center_x, center_y = star_part_x + star_part_s * 5, star_part_y - star_part_s * 5 //計算星星中心點位置
turtle.setpos(center_x, center_y)
turtle.lt(90)
draw_star(star_part_x + star_part_s * 5, star_part_y - star_part_s * 2, star_part_s * 3) //繪制星星
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 2) //同上
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 4)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 7)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 9)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.ht()
time.sleep(5) //設置掛起時間
os._exit(1)