python画国旗的函数 用python画中国国旗( 四 )


size: int类型,正多角形的边长
n: int类型,是几角形
color: str,图形颜色,默认不填色
'''
if color:
aTurtle.begin_fill()
aTurtle.fillcolor(color)
for i in xrange(num):
aTurtle.forward(size)
aTurtle.left(360.0/num)
aTurtle.forward(size)
aTurtle.right(2*360.0/num)
if color:
aTurtle.end_fill()
def draw_5_angle(aTurtle=None, start_pos=(0,0), end_pos=(0,10), radius=100, color=None):
''' 根据起始位置、结束位置和外接圆半径画五角星
args:
aTurtle: turtle对象实例
start_pos: int的二元tuple,要画的五角星的外接圆圆心
end_pos: int的二元tuple,圆心指向的位置坐标点
radius: 五角星外接圆半径
color: str, 图形颜色,默认不填色
'''
aTurtle = aTurtle or turtle.Turtle()
size = radius * math.sin(math.pi/5)/math.sin(math.pi*2/5)
aTurtle.left(math.degrees(math.atan2(end_pos[1]-start_pos[1], end_pos[0]-start_pos[0])))
aTurtle.penup()
aTurtle.goto(start_pos)
aTurtle.fd(radius)
aTurtle.pendown()
aTurtle.right(math.degrees(math.pi*9/10))
draw_n_angle(aTurtle, size, 5, color)
def draw_5_star_flag(times=20.0):
''' 绘制五星红旗
args:
times: 五星红旗的规格为30*20 ,  times为倍数,默认大小为10倍,即300*200
'''
width, height = 30*times, 20*times
# 初始化屏幕和海龟
window = turtle.Screen()
aTurtle = turtle.Turtle()
aTurtle.hideturtle()
aTurtle.speed(10)
# 画红旗
aTurtle.penup()
aTurtle.goto(-width/2, height/2)
aTurtle.pendown()
aTurtle.begin_fill()
aTurtle.fillcolor('red')
aTurtle.fd(width)
aTurtle.right(90)
aTurtle.fd(height)
aTurtle.right(90)
aTurtle.fd(width)
aTurtle.right(90)
aTurtle.fd(height)
aTurtle.right(90)
aTurtle.end_fill()
# 画大星星
draw_5_angle(aTurtle, start_pos=(-10*times, 5*times), end_pos=(-10*times, 8*times), radius=3*times, color='yellow')
# 画四个小星星
stars_start_pos = [(-5, 8), (-3, 6), (-3, 3), (-5, 1)]
for pos in stars_start_pos:
draw_5_angle(aTurtle, start_pos=(pos[0]*times, pos[1]*times), end_pos=(-10*times, 5*times), radius=1*times, color='yellow')
# 点击关闭窗口
window.exitonclick()
if __name__ == '__main__':
draw_5_star_flag()
/code
如何用python turtle画奥运五环?首先画第一环,用虚线画出半径,取该半径的中点,然后从此中点延长虚线,且廷长到的终点是第一环的半径长度 。终点便是第二环的圆心,半径为这条延长线 。第三环同用此法 。下面要说说第二行第一个环,因为上面已有两个环啦,而且两环的半径之间已有一条虚线,那么就在这条虚线做垂直平分线,然后做一个倒的等腰三角形 , 它的腰是圆的半径,它的顶点是该环的圆心,第五环皆用此法 。
五环是由皮埃尔·德·顾拜旦先生于1913年构思设计的奥林匹克运动会的会徽,是由《奥林匹克宪章》确定的,也被称为奥运五环标志,它是世界范围内最为人们广泛认知的奥林匹克运动会标志 。它由5个奥林匹克环套接组成,由蓝、黄、黑、绿、红5种颜色 。环从左到右互相套接,上面是蓝、黑、红环 , 下面是是黄、绿环 。整个造形为一个底部小的规则梯形 。最初的解释是五种颜色代表各国国旗的颜色,后来又将5个不同颜色的圆环解释为五大洲的象征 。
【python画国旗的函数 用python画中国国旗】python画国旗的函数的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于用python画中国国旗、python画国旗的函数的信息别忘了在本站进行查找喔 。

推荐阅读