PK Creative Spring Festival, I am participating in the “Spring Festival Creative Submission Contest”, please see: Spring Festival Creative Submission Contest “,
sequence
After last time using Python Turtle to draw red envelope cover, out of control, today I will draw a dumpling, Chinese New Year, come to eat golden dumplings. Effect:
Began to draw
Add background
A New Year or the red background is the most beautiful, this time still use the last background pictures, interested can download their favorite background pictures from the Internet, remember the picture format is PNG and GIF format, or it will report an error
turtle.bgpic("img_1.png")
Copy the code
I used a background image that you can download and use directly
conceived
Let’s simply analyze the shape of the dumpling, the main body is an ellipse, and some dumplings of the painting, the painting of the dumpling is a semicircle, the main ellipse, we can use two ellipses to synthesize, that is, the whole dumpling has many semicircles. Turtle’s circle function takes two parameters, the first parameter is radius, which indicates the size of the circle to be drawn, and the other parameter indicates the radian of the circle. This allows us to draw not only a perfect circle, but also various ellipses.
Draw the main body
For the body of the dumpling, draw a lower arc with a radius of 200 and a radian of 100 and fill it with gold color
# Draw the first half circle turtle.penup() turtle.goto(-100, 0) turtle.left(-50) turtle.pendown() turtle.color("#FFCC33") turtle.begin_fill() turtle.circle(200, 100) turtle.end_fill()Copy the code
As is shown in
Draw the symmetrical upper half of the arc, with a radius of 200 and a radian of 100, and pay attention to the position and Angle at which the brush starts
Let’s just look at the code
Turtle.penup () turtle.goto(-100, 0) turtle.pendown() turtle.color("#FFCC33") turtle.begin_fill() turtle.circle(-200, 100) turtle.end_fill()Copy the code
So let’s run it again and look at the picture
Here the main body of the dumpling is good, the following is to draw the dumpling lace.
Let’s go back to the origin (-100, 0), adjust the Angle of the brush, set the radius and radian of the edge, look at the first edge, we fill the dumpling lace with different colors. Here we set the radius of 🌹 to 27 and the radian to 180, which is a semicircle.
# Draw the lace turtle.penup() turtle.goto(-100, 0) turtle.right(180) turtle.pendown() turtle.color("#CC9933") turtle.begin_fill() turtle.circle(-27, 180) turtle.end_fill()Copy the code
Look at the effect of the first lace
Next, I drew the other LACES in turn. The second one was a little special and needed to move the coordinate of the brush. I took the code of the second lace out separately
turtle.penup()
turtle.goto(-56, 31)
turtle.right(190)
turtle.pendown()
turtle.color("#CC9933")
turtle.begin_fill()
turtle.circle(-27, 180)
turtle.end_fill()
Copy the code
The rest of the lace can be made into a loop, the body of the loop code is as follows:
turtle.right(198)
turtle.color("#CC9933")
turtle.begin_fill()
turtle.circle(-27, 180)
turtle.end_fill()
Copy the code
The results
If you are interested in Python, you will get a little bit of inspiration
conclusion
Turtle drawing is the main of the coordinates of the screen, and the steering Angle of the brush to clear, want to draw a perfect graphics, through accurate calculation, I drew this lace is slightly coarse, is my circle radius, and coordinate calculation, is not conducive to the whole of the fine, accurate to decimal point, but in the notebook sketches also cost me a lot of paper, During the holidays move brain move hands, is also very good, at home when drawing this, also caused the interest of primary school students, they do not write homework, around my computer, see with gusto, but also put forward interesting questions, this is also a contribution to the flowers of the motherland.