如何用 Python 代码绘制赏月美景?

利用下班的空暇时间写了一段关于中秋节的代码,可以实现自动绘制山川、运毒和月亮,以及写出美好的诗句,让你深切陶醉于中秋佳节的节日气氛中。本文中主要是使用到了Python中的turtle库、time库以及pygame库,可以更好的实现动态的效果。如何用 Python 代码绘制赏月美景?_第1张图片我们可以使用 turtle 库绘制月亮、云朵、山以及古诗,游戏模块使用 pygame 库,配上美美的背景音乐。

1. 导入所需要的库(turtle 库、time 库、pygame 库)

1 '''2 Function: 中秋赏月3 Author: 向阳逐梦4 '''5 import turtle6 import time7 import pygame
使用 import 导入需要使用的函数库,实现需要的功能。本文章实现的功能是绘制月亮、云朵和山川的图案和显示古诗句。                                       
2. 绘制月亮和云朵
1def drawMoon():    #绘制月亮 2 turtle.penup()   #画笔拿起  3turtle.goto(-150, 0)  4turtle.fillcolor((255, 215, 0))   #圆月的颜色 5 turtle.pendown()   #画笔放下  6turtle.begin_fill() 7 turtle.circle(112) 8 turtle.end_fill()  #turtle.begin_fill()到turtle.end_fill() 颜色填充9def drawCloud(): #绘制云朵   10turtle.penup()   11turtle.goto(-500, 200)  12 turtle.fillcolor((245, 245, 245))   13turtle.pencolor((255, 255, 255))   14turtle.pensize

你可能感兴趣的:(命令模式,代理模式)