With Python, I'll take you to enjoy it for a month when the Mid Autumn Festival is coming

Dai mubai 2021-09-15 09:18:50

I'm participating in the Mid Autumn Festival Creative submission competition

Preface

Happy moon cake festival ahead of time ~

We'll use it today python Enjoy a wave of moon ~

I don't say much nonsense , Let's start happily ~

development tool

Python ** edition :3.6.4

Related modules :

pygame modular ;

As well as some python Built in modules .

Environment building

install Python And add to environment variable ,pip Install the relevant modules required .

Introduction of the principle

The principle is very simple , First find a picture on the Internet that feels simple ( No, use it turtle Library is not easy to draw T_T) A beautiful picture of appreciating the moon , And then use it turtle Just imitate the painting .

The first is initialization ( Loading music for the occasion, etc

''' initialization '''
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 the Mid Autumn Festival ~')
turtle.colormode(255)
turtle.bgcolor((16, 78, 139))
turtle.speed(10)
 Copy code 

Then draw the moon ( It's actually a round picture ):

''' 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 code 

And then there was 5 The cloud of Maoqian special effect ( 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 code 

A dime special effect mountain ( picture ):

''' Huashan '''
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 code 

And a mid autumn festival blessing that celebrates the Millennium ( picture ):

''' Writing a poem '''
def writePoetry():
turtle.penup()
turtle.goto(400, -150)
turtle.pencolor((255, 255, 0))
# Verse 
potery = [" but \n Would like to \n people \n Long \n For a long time \n", " thousand \n in \n common \n Chan \n Juan \n"]
# Verse position ( You can design and add ), best 2/4 A five character poem 
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 code 

16600f74cad24967ba2e0f0d3af525e3.jpg

Please bring the original link to reprint ,thank
Similar articles

2021-09-15

2021-09-15

2021-09-15

2021-09-15