如何用python写赏月工具

发布时间:2021-09-24 15:07:26 作者:柒染
来源:亿速云 阅读:106

这篇文章给大家介绍如何用python写赏月工具,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

一年中秋至 又见圆月时

如何用python写赏月工具

导语

假设农历八月十五,程序员错过了今年的中秋圆月。

如何用python写赏月工具

程序员的苦只有他们寄几知道

bug,bug,bug,bug,bug,bug……

吃饭时在改bug,走路时在改bug,约会时在改bug,结婚时在改bug

就连中秋佳节也还!在!改!bug!

如何用python写赏月工具

不过做为一枚上知《边城》下知编程的程序员,没有什么可以难倒他

“不就是中秋的圆月亮吗?”三分钟以后…程序员自己用Python画了一个

Python版中秋圆月!甚至可以的话,我每天都可以赏月过中秋~

如何用python写赏月工具

正文

环境安装:使用turtle绘制、游戏模块pygame模块照旧。

(1)首先绘制圆月。

def drawMoon():
	turtle.penup()   #画笔拿起
	turtle.goto(-150, 0)
	turtle.fillcolor((255, 215, 0))   #圆月的颜色
	turtle.pendown()   #画笔放下
	turtle.begin_fill()
	turtle.circle(112)
	turtle.end_fill()  #turtle.begin_fill()	到turtle.end_fill() 颜色填充

(2)然后绘制云层。

稍微有点儿复杂,因为云是飘动的,所以比月亮难一点。

def drawCloud():
   turtle.penup()
   turtle.goto(-500, 200)
   turtle.fillcolor((245, 245, 245))
   turtle.pencolor((255, 255, 255))
   turtle.pensize(5)
   turtle.pendown()
   turtle.forward(250)
   def cloud(mode='right'):
      for i in range(90):
         turtle.pensize((i+1)*0.2+5)
         turtle.right(1) if mode == 'right' else turtle.left(1)
         turtle.forward(0.5)
      for i in range(90):
         turtle.pensize(90*0.2+5-0.2*(i+1))
         turtle.right(1) if mode == 'right' else turtle.left(1)
         turtle.forward(0.5)
   cloud()
   turtle.forward(100)
   cloud('left')
   turtle.forward(600)

(3)绘制山川。

def drawMountain():
   turtle.penup()
   turtle.goto(-500, -250)
   turtle.pensize(4)
   turtle.fillcolor((36, 36, 36))
   turtle.pencolor((31, 28, 24))
   turtle.pendown()
   turtle.begin_fill()
   turtle.left(20)
   turtle.forward(400)
   turtle.right(45)
   turtle.forward(200)
   turtle.left(60)
   turtle.forward(300)
   turtle.right(70)
   turtle.forward(300)
   turtle.goto(500, -300)
   turtle.goto(-500, -300)
   turtle.end_fill()

(4)设置界面,进界面就有音乐播放。

def initTurtle():
   pygame.mixer.init()
   pygame.mixer.music.load('bgm.mp3')
   pygame.mixer.music.play(-1, 20.0)
   turtle.hideturtle()
   turtle.setup(1000, 600)
   turtle.title('中秋赏月')
   turtle.colormode(255)
   turtle.bgcolor((193, 210, 240))
   turtle.speed(10)

(5)绘制诗句。

def writePoetry():
	turtle.penup()
	turtle.goto(400, -150)
	turtle.pencolor((250, 240, 230))
	# 诗句
	potery = ["\n明\n月\n几\n时\n有\n", "把\n酒\n问\n青\n天\n"]
	# 诗句位置(可自行设计添加), 最好2/4句五言诗
	coordinates = [(300, -150), (200, -150), (100, -150)]
	for i, p in enumerate(potery):
		turtle.write(p, align="center", font=("STXingkai", 50, "bold"))
		if (i + 1) != len(potery):
			time.sleep(2)
			turtle.goto(coordinates[i])

效果图:

如何用python写赏月工具

如何用python写赏月工具

关于如何用python写赏月工具就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. Mac上可以用哪些工具写python
  2. 如何用python写剪刀石头布

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python

上一篇:管理和维护RHCS集群的方法有哪些

下一篇:python中数据类型的示例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》