Home >headlines >Grandpa: What is Peppa Pig? Page: Python can draw it in 10 seconds

Grandpa: What is Peppa Pig? Page: Python can draw it in 10 seconds

藏色散人
藏色散人forward
2019-01-21 11:26:234213browse

Since last night, the circle of friends has been flooded with a careless advertisement. Many friends said: I cried when I saw it. When the grandfather heard his son say "I'm not coming back" on the phone, it was a heavy blow. The father missed his son and grandson and always wanted to give them the best.

Recommended reference study: "Python Tutorial"

If your child asks you for Peppa Pig, you can do nothing but like in the video You can also go to the store to buy one, or you can use Python to draw one. (The dynamic image is a bit stuck, but the code runs smoothly)

Grandpa: What is Peppa Pig? Page: Python can draw it in 10 seconds

#The library used to draw Peppa Pig today is turtle. I used turtle library to draw the five-star red flag to pay tribute to the Asian Games athletes. , I used Python to draw the five-star red flag

Grandpa: What is Peppa Pig? Page: Python can draw it in 10 seconds

Before, I also used the turtle library to draw a beautiful spiral with one line of code. What crazy functions can be achieved with one line of code?

Grandpa: What is Peppa Pig? Page: Python can draw it in 10 seconds

Environment

Language: Python3.6

Editor: Pycharm

turtle Library: It is a built-in library of Python and can be imported directly.

import turtle

Basic usage of turtle library

Before drawing graphics, first master some basic usage of turtle library drawing.

turtle.begin_fill():准备开始填充图形。
turtle.goto(x, y):将画笔移到坐标的位置。
turtle.forward(n):向当前画笔方向移动 n 像素长。
turtle.left(m):逆时针移动 m°
turtle.right(m):顺时针移动 m°
turtle.end_fill():图形填充完成。

Code Analysis

First we set the initial information, including the size of the brush, the brush color and fill color, the size of the main window and the brush speed.

Grandpa: What is Peppa Pig? Page: Python can draw it in 10 seconds

Then draw the nose part, there are more codes, the following are some codes, all codes can be obtained by replying "Page" on the official account.

Grandpa: What is Peppa Pig? Page: Python can draw it in 10 seconds

The other parts will not be listed one by one. The methods are similar. After mastering some basic usage of turtle library drawing, you can slowly debug the basics yourself. .

Finally, I wish everyone revenge in the Year of the Pig!


Statement:
This article is reproduced at:Python知识圈. If there is any infringement, please contact admin@php.cn delete