The Mid-Autumn festival to see the full moon

Introduction:

Suppose the lunar August 15, programmers miss this year’s Mid-Autumn full moon.

Programmers’ woes are only known to them

Bug, bug, bug, bug, bug, bug…

I bug you at dinner, I bug you when you walk, I bug you when you date, I bug you when you get married

Even the Mid-Autumn Festival also! In! To change! A bug!

But as a programmer who knows how to write bordertown and how to write code, what can stop him

“Isn’t it the full moon of Mid-Autumn Festival?” Three minutes later… The programmer drew one himself in Python

Full Moon in Python! If I could, I could enjoy the Mid-Autumn Festival every day

The body of the

Environment setup: Use Turtle to draw, game module PyGame module as usual.

(1) First draw the full moon.

def drawMoon(): Turtle.penup () # Brush pick up turtle.goto(-150, 0) turtle.fillcolor((255, 215,) Turtle.begin_fill () turtle.circle(112) turtle.end_fill() #turtle.begin_fill() Go to turtle.end_fill() color to fillCopy the code

(2) Then draw the clouds.

It’s a little bit more complicated because clouds float, so it’s a little bit more difficult than the moon.

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)Copy the code

(3)Draw mountains and rivers.

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()
Copy the code

(4)Set the interface, into the interface there is music playing.

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 (' Mid-Autumn moon ') Turtle.colorMode (255) turtle.bgColor ((193, 210,) 240)) turtle.speed(10)Copy the code

(5)Draw verses.

def writePoetry(): Pencolor ((250, 240, 230)) # verse potery = ["\n \n \n \n \n \n few \n \n time \n have \n", Coordinates = [(300, -150), (200, -150), (100, -150)] for I, coordinates = [(300, -150), (200, -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])Copy the code

Effect:

​​​conclusion

Mid-Autumn moon, mu Mu zi will take you to worship for the first ha ~

Production is not easy, remember one key three even oh!! If you need this article complete code + image material.

Python novice installation package, free activation code, and more Python information, source base see: [private letter xiaobian 06] can be free to receive!!