用户:BEE王查看:0 回复:0 评论:0 创建时间:2020-01-31T23:16:32
【作品展示】

【作品介绍】
标准五星红旗,可定制大小
【作品源代码】
##### Standard National flag of China #####
import math
import turtle
myPen = turtle.Pen()
myPen.speed(0)
########## Set flag size ############
flagLength = 800 # Flag length
flagWidth = flagLength*2/3 # Flag width
############ Begin: draw rectangular ############
myPen.fillcolor('red')
myPen.penup()
myPen.goto(-flagLength/2, -flagWidth/2) # Left-bottom corner of the flag
myPen.begin_fill()
for i in range(2):# Draw rectangular
myPen.forward(flagLength)
myPen.left(90)
myPen.forward(flagWidth)
myPen.left(90)
myPen.end_fill()
############## End: draw rectangular #############
############## Begin: define myStar function ###############
def myStar(star_radius=100, star_angle = 0, star_color='yellow'):
## Draw a star with its center at present pen position
## Turtle pen name: myPen
## Star_radius: length between center to corner; star_angle: 0-one star corner point to up
myPen.fillcolor(star_color)
myPen.begin_fill()
myPen.setheading(0)#Set pen head pointing to right
myPos = myPen.position()#Get current pen positions
x = myPos[0]-star_radius*math.sin((72-star_angle)/180*math.pi)#Calculate the x position of the star's corner
y = myPos[1]+star_radius*math.cos((72-star_angle)/180*math.pi)#Calculate the y position of the star's corner
myPen.goto(x,y)
myPen.right(star_angle)#Rotate the star
for i in range(5):#Draw the star
myPen.forward(star_radius*0.951*2)
myPen.right(144)
myPen.end_fill()
############## End: define myStar function ###############
################## Begin: draw stars #####################
## Calculate star size
Star_big_diameter = flagWidth*0.3 # Size of the big star
Star_喵all_diameter = flagWidth*0.1 # Size of the 喵all star
Star_radius = [ Star_big_diameter/2, Star_喵all_diameter/2, Star_喵all_diameter/2, Star_喵all_diameter/2, Star_喵all_diameter/2 ]
## Calculate star center positions
Big_star_center = [-flagLength/2+flagLength/2/3, flagWidth/2/2]
Small_star_1st_center = [-flagLength/2+flagLength/2/15*10, flagWidth/2/10*8]
Small_star_2nd_center = [-flagLength/2+flagLength/2/15*12, flagWidth/2/10*6]
Small_star_3rd_center = [-flagLength/2+flagLength/2/15*12, flagWidth/2/10*3]
Small_star_4th_center = [-flagLength/2+flagLength/2/15*10, flagWidth/2/10*1]
Star_centers = [ Big_star_center, Small_star_1st_center, Small_star_2nd_center, Small_star_3rd_center, Small_star_4th_center ]
## Calculate star angle
Angle_big_star = 0
Angle_1st_喵all_star = -90-math.atan(3/5)/math.pi*180
Angle_2nd_喵all_star = -90-math.atan(1/7)/math.pi*180
Angle_3rd_喵all_star = -90+math.atan(2/7)/math.pi*180
Angle_4th_喵all_star = -90+math.atan(4/5)/math.pi*180
Star_angles = [ Angle_big_star, Angle_1st_喵all_star, Angle_2nd_喵all_star, Angle_3rd_喵all_star, Angle_4th_喵all_star ]
for i in range(5):## Draw stars
myPen.goto(Star_centers[i][0], Star_centers[i][1]) # Center of the star
myStar(Star_radius[i], Star_angles[i])
################## End: draw stars #####################
myPen.hideturtle()# hide pen
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn