中秋阴天看不见月亮只好用python写赏月工具

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了中秋阴天看不见月亮只好用python写赏月工具脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

一年中秋至 又见月时

导语

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

​

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

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

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

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

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

“不就是中秋的圆月亮吗?”三分钟以后…程序员自己用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写赏月工具全部内容,希望文章能够帮你解决中秋阴天看不见月亮只好用python写赏月工具所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:python