Introduction:

But the one

2021 Mid-Autumn Festival is only 14 days away!

Every family will enjoy the moon and eat moon cakes

It is not easy to get together. It is important to have a happy reunion.

BUT xiaobian did not like to eat moon cakes from childhood to childhood, the family would buy pictures at home, every year is symbolic to eat a little

I don’t think I will take a few days off this year, 2-3 days at most, and I probably won’t be able to go home. I definitely won’t buy it.

Harm, so xiaobian and borrow Python to draw moon cakes. Take it as I ate it

The body of the

Are you tired of traditional moon cakes? Let’s do something special.

This chocolate mooncake is filled with exquisite fillings and a variety of fresh flavors to stimulate your taste buds.

A box of 3, fillings are different, give you a different Mid-Autumn festival novelty.

Hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey, hey

Traditional moon cakes:

​​

Chocolate mooncake:

Cough cough cough! Just play it by ear.

It’s time to start painting moon cakes

(1) Environment installation.

Again, the universal library: Turtle. It comes with it so you don’t need to install it separately.

(2) First create a mooncake.py file.

六四风波​​

六四风波

Input code:

import turtle
Copy the code

And then we have our pen function defined, which is the brush.

t = turtle.Pen()
Copy the code

(3) Paint the moon cake according to the stamen pattern on the far right of the chocolate moon cake that I like.

The most outer circle of the moon cake is like a wave, we first draw the outer circle of the moon cake pattern.

Want to draw the curved edges of the mooncake? We need to use the circle directive.

Code:

For I in range(30): # With the for loop, you can repeat the above figure multiple times. Until it's drawn in a circle. # we move the brush T 200 pixels in the direction of the arrow. # We draw a small arc. 0) t.r d.light (180) t.r d.light (12)Copy the code

(4) Color the moon cake. Chocolate words black scatter!

Here we will use these:

  • Begin_fill () & end_fill() help us fill the graph

  • T.color () sets the brush t to the specified color

Code:

Import turtle t = turtle.pen () t.speed(0) # to control the drawing speed turtle.colormode(255) # to tell Python that we use RGB to specify the color t.color((0,0,0)) # indicates that the color consists of red 0 green 0 blue 0 chocolate color pure black. for i in range(30): Fill () # begin_fill() # begin_fill() # begin_fill() # begin_fill() # begin_fill() # begin_fill( The graphics between end_fill() will fill in the colors we specifyCopy the code

As follows:

(5) Start of free creation.

Add this code:

T.color ((192,192)) t.penup() t.goto(0,-180) t.pendown() t.Wright (30) t.Circle (180,-360) t.Penup () t.goto(0,0) For I in range(5): t.color('brown') t.width(5) t.frost (80) t.dot(30) t.goto(0,0) t.light (360/5)Copy the code

The effect is as follows:

Cough, what about chocolate mooncakes with three fillings? Now only a sprinkle continues.

Red and green classic colorThis color seems a little ugly, you can make your own color can be modified!

conclusion

Try it out for yourself. I must have been looking for that color scheme for half an hour. Production is not easy, remember one key three even oh!!

Chocolate I tried my best! 23333~ Ugly ugly UGLY I actually feel this color son also line, ha ha ha

If you need the full project source code, the starter package activation code, and more Python resources

Source code base see: [private letter xiaobian 06] can be free oh!!