Python的turtle模块画国旗主要用到两个函数:draw_rentangle和draw_star。
至于函数的调用就和我们学的C,C++是一样的。对于turtle画国旗的程序中,首先是查找国旗的画法,才能用程序实现。自己在实现的过程中主要是对turtle.circle()没有准确掌握,所以花了一些不必要的时间。turtle.circle画弧时,海龟(turtle)的方向就是弧的切线方向,也就是说turtle的垂直方向就是圆心在的直线上,给定参数radius就可以画了,程序中第二注意的地方就是小五角星和大五角星的位置关系,主要是程序中的turtle.left(turtle.towards(center_x,center_y)-turtle.heading()),当然,我看有的人用了round()函数来获取近似值,但是,默认的已经足够了。下面是本人写的程序和结果演示。
import time import turtle import os ''' 想要学习Python?Python学习交流群:984632579满足你的需求,资料都已经上传群文件,可以自行下载! ''' def draw_rectangle(start_x,start_y,rec_x,rec_y): turtle.goto(start_x,start_y) turtle.color('red') turtle.fillcolor('red') turtle.begin_fill() for i in range(2): turtle.forward(rec_x) turtle.left(90) turtle.forward(rec_y) turtle.left(90) turtle.end_fill() def draw_star(center_x,center_y,radius): turtle.setpos(center_x,center_y) #find the peak of the five-pointed star pt1=turtle.pos() turtle.circle(-radius,72) pt2=turtle.pos() turtle.circle(-radius,72) pt3=turtle.pos() turtle.circle(-radius,72) pt4=turtle.pos() turtle.circle(-radius,72) pt5=turtle.pos() #draw the five-pointed star turtle.color('yellow','yellow') turtle.fill(True) turtle.goto(pt3) turtle.goto(pt1) turtle.goto(pt4) turtle.goto(pt2) turtle.goto(pt5) turtle.fill(False) #start the project turtle.speed(5) turtle.penup() #draw the rectangle star_x=-320 star_y=-260 len_x=660 len_y=440 draw_rectangle(star_x,star_y,len_x,len_y) #draw the big star pice=660/30 big_center_x=star_x+5*pice big_center_y=star_y+len_y-pice*5 turtle.goto(big_center_x,big_center_y) turtle.left(90) turtle.forward(pice*3) turtle.right(90) draw_star(turtle.xcor(),turtle.ycor(),pice*3) #draw the small star turtle.goto(star_x+10*pice,star_y+len_y-pice*2) turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading()) turtle.forward(pice) turtle.right(90) draw_star(turtle.xcor(),turtle.ycor(),pice) #draw the second star turtle.goto(star_x+pice*12,star_y+len_y-pice*4) turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading()) turtle.forward(pice) turtle.right(90) draw_star(turtle.xcor(),turtle.ycor(),pice) #draw the third turtle.goto(star_x+pice*12,star_y+len_y-7*pice) turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading()) turtle.forward(pice) turtle.right(90) draw_star(turtle.xcor(),turtle.ycor(),pice) #draw the final turtle.goto(star_x+pice*10,star_y+len_y-9*pice) turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading()) turtle.forward(pice) turtle.right(90) draw_star(turtle.xcor(),turtle.ycor(),pice) turtle.ht() time.sleep(3) os._exit(1)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
python,turtle,国旗
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。