I am participating in the Mid-Autumn Festival creative submission contest

preface

Everyone in advance happy month cake festival ~

Let’s enjoy the moon in Python today

Without further ado, let’s begin happily

The development tools

Python ** version: 3.6.4

Related modules:

Pygame module;

And some modules that come with Python.

Environment set up

Install Python and add it to the environment variables. PIP installs the required related modules.

Introduction of the principle

In fact, the principle is very simple, first on the Internet to find a simple feeling (not simple points using turtle library is not good to draw T_T) beautiful moon, and then use turtle library to imitate the painting on the line.

The first is initialization (loading the appropriate music and so on

Initialize.
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('Enjoy the moon with Pikachu in Mid-Autumn Festival ~')
  turtle.colormode(255)
  turtle.bgcolor((16.78.139))
  turtle.speed(10)
Copy the code

Then draw the moon:

"Draw the moon."
def drawMoon() :
  turtle.penup()
  turtle.goto(-150.0)
  turtle.fillcolor((212.175.55))
  turtle.pendown()
  turtle.begin_fill()
  turtle.circle(112)
  turtle.end_fill()
Copy the code

And then a 50 cent cloud (picture) :

"' painting clouds" '
def drawCloud() :
  turtle.penup()
  turtle.goto(-500.200)
  turtle.fillcolor((245.245.245))
  turtle.pencolor((220.220.220))
  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

A ten-cent mountain (photo) :

"' painting mountain" '
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

And a Mid-Autumn Festival blessing (picture) :

"' writing poetry" '
def writePoetry() :
  turtle.penup()
  turtle.goto(400, -150)
  turtle.pencolor((255.255.0))
  # lines
  potery = ["But \n wish \n people \n long \n long \n"."Thousand \n li \n total \n chan \n Juan \n"]
  # Poem position (can be designed to add), preferably 2/4 sentences of five words
  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])
Copy the code