开发者

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

目录
  • 导语
  • 正文
    • (1)首先绘制圆月。
    • (2)然后绘制云层。
    • (3)绘制山川。
    • (4)设置界面,进界面就有音乐播放。
    • (5)绘制诗句。
  • 总结

    一年中秋至 又见圆月时

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

    导语

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

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

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

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

    吃饭时在改bug,走路时在改b编程客栈ug,约会时在改bug,结婚时在改bug

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

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

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

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

    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)qLGvbesS)
       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.musqLGvbesSic.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写赏月工具的文章就介绍到这了,更多相关python 月亮内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

    0

    上一篇:

    下一篇:

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    最新开发

    开发排行榜