I am participating in the Mid-Autumn Festival Creative Submission contest, please see: Mid-Autumn Festival Creative Submission Contest for details

The Mid-Autumn Festival is coming soon

Are you guys right?

I could hardly contain my excitement

The mood has already flown home/travel destination

(This article hides the leader)

Before writing this article

I am on the net

Have seen a lot about

Mid-Autumn Festival of all kinds of jokes and poems

See something “Mid-Autumn Festival”, “wine”

Words like that

I want to:

This is not “single charge” “double charge”

Probably ancient and modern poets

I think he was one of the first hip-hop artists

And the so-called doggerel

Freestyle is!

Here’s how to do it

Mid-Autumn Flow as a song:

When is the moon

Beer today

Looking at the moon Palace rabbit

Why is he like a dog

However, goose Mid-Autumn Festival flow needs a background. Here, in order to conform to the scope of Mid-Autumn Festival and family happiness, we choose thick middle-aged and elderly emoticons:

Python has a built-in module called Turtle, commonly known as Turtle Drawing, which is based on the Tkinter module and has some simple drawing functions. Although Turtle is difficult to draw very complex effects, it is good for painting biao strokes.

1). Drawing steps ****

Create the canvas and set the background color, then draw the full moon, white clouds, mountains, and text in turn. Turtle is very easy to use. If you have any questions, please refer to the official documentation. Here are some common methods:

  • Create canvas: Defines an initialization function that sets the canvas, background color, and drawing speed.
  • Moon: Position the starting point, specify the radius, draw a circle and fill it with color.
  • White cloud: Set line width and color, draw a straight line; The arc part is slightly more complicated, and the line width should be changed continuously with the Angle change — gradually increasing the line width for the first 90° and gradually decreasing the line width for the last 90° to get the effect in the picture.
  • Mountains: Draw a closed polygon based on the shape and fill it with color.
  • Text: The Wrtie () function in the Turtle module writes text directly to the diagram, supporting custom fonts and sizes.

2). Source code step

First, introduce the Turtle and time modules:

import turtle
import time
Copy the code

Define a background color: BC=’DodgerBlue4′ then start drawing the moon, which is a circle and fill it with yellow

def draw_moon():
    turtle.pencolor(BC)
    turtle.fillcolor('Gold')
    turtle.penup()
    turtle.goto(-150, 0)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(110)
    turtle.end_fill()
Copy the code

Draw our “Mid-Autumn Flow” in the form of words:

def draw_words(): Turtle.penup () turtle.pencolor('Yellow') turtle.goto(400, -150) turtle.write(" Ming \n \n \n several \n \n" have \n, align="center", Font =("STXingkai", 50, "bold") turtle.sleep(1) turtle.goto(300, -150) turtle.write(" distance \n wan \n month \n palace \n rabbit \n, align="center", Font =("STXingkai", 50, "bold") turtle. Sleep (1) turtle. Goto (100, -150) turtle. font=("STXingkai", 50, "bold"))Copy the code

Use a few broken lines to draw the mountains

def draw_mountain():
    turtle.fillcolor('grey21')
    turtle.pencolor('grey31')
    turtle.pensize(4)
    turtle.penup()
    turtle.goto(-500, -250)
    turtle.begin_fill()
    turtle.pendown()
    turtle.left(15)
    turtle.forward(400)
    turtle.right(30)
    turtle.right(30)
    turtle.forward(200)
    turtle.left(40)
    turtle.forward(300)
    turtle.right(300)
    turtle.forward(300)
    turtle.goto(500, -300)
    turtle.goto(-500, -300)
    turtle.end_fill()
    
Copy the code

And then there’s the cloud track

def draw cloud() : Angle = 3 # disize = 0.6 # increase/decrease line width psize = 5 # Initial line width turtle. pencolor('whiteSmoke') turtle.pencolor( 'Gainsboro' ) turtle.pensize(psize) turtle.penup() turtle.goto(-500, 200) turtle.pendown() turtle.forward (250) for i in range (30) : psize += disize turtle.pensize(psize) turtle. right (angle) turtle. forward (step) for i in range (30) : psize -= disize turtle.pensize(psize) turtle.right (angle) turtle.forward(step) turtle.forward (100) for i in range (30)  : psize += disize turtle.pensize(psize) turtle.left (angle) turtle. forward(step) for i in range (30) : psize -= disize turtle.pensize(psize) turtle.left(angle) turtle.forward(step) turtle.forward(200)Copy the code

Finally, write the main method and integrate all the brushes to complete the freestyle.

def draw init): turtle.hideturtle() turtle.setup(1000, Def main()" draw_moon() draw_cloud() draw_mountain() draw_moon() draw_moon() draw_cloud() draw_mountain() draw_moon() draw_moon() draw_moon() draw_cloud() draw_mountain() draw_words() turtle.exitonclick() if __name__ === '__main__' main()Copy the code