My girlfriend especially likes Peppa Pig, she can’t stop seeing Peppa Pig dolls, so I recently studied Python’s turtle library, in short, this library is used to paint on the computer, you can control a brush, including setting its color speed and other parameters, you can also control its position and direction of movement, so I had a whim that I could use turtle to paint a Peppa Pig to make my girlfriend happy.
Let’s take a look at the final result.
Installation
Before painting, we need to install the libraries we use, it’s super easy, just use pip to install them.
pip3 install turtle
Analysis
Piggy looks simple, but it is still complicated to draw. We will divide it into nose, head, eyes, ears, mouth, body, hands, feet, tail and other parts to draw separately.
As usual, we will introduce the library turtle we will use today and do some basic settings
Five senses
The first step is of course to draw out the nose, eyes, ears, mouth and other five senses.
See the results.
Body
After the five senses are drawn is the body and limbs, in fact, it is not complicated, the main thing is to calculate the corresponding position can be.
And then look at the effect:
Entry functions
Finally, it is enough to integrate the functions of each part into a single entry function.
def main():
setting()
nose(-100, 100)
head(-69, 167)
ears(0, 160)
eyes(0, 140)
cheek(80, 10)
mouth(-20, 30)
body(-32, -8)
hands(-56, -45)
foot(2, -177)
tail(148, -155)
t.done()
if __name__ == ‘__main__’:
main()
This is the end of the work.
Summary
Today, Paisen sauce will take you together with the Piggy Peach painted with the program, due to the limited space in the text omitted part of the code, the need for partners according to the end of the way to get their own. In fact, partners can play their own imagination, sometimes the surprise does not need to spend a lot of money, just a little heart can make the other half happy for a long time, I wish you all happy every day.