What is Page, Python tells you!
Today,
was hit by the commercial "What is Peppa Pig"?
Page is obviously a comedy character, but
made everyone cry.
1. "What is Page"? ? ?
It’s almost the Chinese New Year.
My grandfather in the countryside called his grandson in the city.
The grandson said he wanted “Peppa”,
In order to fulfill his grandson's wish, Grandpa
began to search for Peppa Pig all over the village.
The grandfather’s words on the phone at the beginning of the film are very touching.
Grandpas all over the world love their grandchildren in this way.
The audience was immediately attracted by Have an empathic mentality.
The sentence "What is Peppa Pig?"
paved the way for Grandpa to search for Peppa Pig.
In the end, Grandpa found Peppa Pig's bones and bones.
is the cutest Peppa Pig in the world that the owner has ever seen!
#I don’t know how you feel after reading it, but I cried after reading it. I saw that netizens also left messages one after another, saying that they were both crying and laughing...
I felt a little sad when I saw my grandpa searching for Peppa Pig all over the village. For this reason, I want to use pure Python to tell Grandpa, what is Page?
2.This is Peppa Pig!
Basic idea: Select the size of the drawing board, set the color and thickness of the brush, position it well, and draw the nose, head, ears, eyes, cheeks, mouth, body, hands, feet, and tail in sequence, and you're done.
As we all know, turtle is an interesting module built into Python, commonly known as turtle drawing. It is based on the tkinter module and provides some simple drawing tools.
In turtle drawing, we can write instructions to make a virtual (imaginary) turtle move back and forth on the screen. This turtle is carrying a pen, and we can have the turtle use this pen to draw lines wherever it moves. By writing code to move the turtle in a variety of cool patterns, we can draw amazing pictures. Using turtle mapping, not only are we able to create impressive visuals with just a few lines of code, but we can also follow the turtle to see how each line of code affects its movement. This can help us understand the logic of the code. Therefore, turtle plotting is often used as a way for novices to learn Python. For more detailed functions and knowledge, please refer to the official documentation: http://www.php.cn/course/796.html.
After understanding the usage of tuttle, you can start actual combat.
Code example:
from turtle import* def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南) begin_fill()#准备开始填充图形 a=0.4 for i in range(120): if 0<=i<30 or 60<=i<90: a=a+0.08 left(3) #向左转3度 forward(a) #向前走a的步长 else: a=a-0.08 left(3) forward(a) end_fill()#填充完成 penup() setheading(90) forward(25) setheading(0) forward(10) pendown() pencolor(255,155,192)#画笔颜色 setheading(10) begin_fill() circle(5) color(160,82,45)#返回或设置pencolor和fillcolor end_fill() penup() setheading(0) forward(20) pendown() pencolor(255,155,192) setheading(10) begin_fill() circle(5) color(160,82,45) end_fill() def head(x,y):#头 color((255,155,192),"pink") penup() goto(x,y) setheading(0) pendown() begin_fill() setheading(180) circle(300,-30) circle(100,-60) circle(80,-100) circle(150,-20) circle(60,-95) setheading(161) circle(-300,15) penup() goto(-100,100) pendown() setheading(-30) a=0.4 for i in range(60): if 0<=i<30 or 60<=i<90: a=a+0.08 lt(3) #向左转3度 fd(a) #向前走a的步长 else: a=a-0.08 lt(3) fd(a) end_fill() def cheek(x,y):#腮 color((255,155,192)) penup() goto(x,y) pendown() setheading(0) begin_fill() circle(30) end_fill() def mouth(x,y): #嘴 color(239,69,19) penup() goto(x,y) pendown() setheading(-80) circle(30,40) circle(40,80) def setting(): #参数设置 pensize(4) hideturtle() #使乌龟无形(隐藏) colormode(255) #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内 color((255,155,192),"pink") setup(840,500) speed(10) def main(): setting() #画布、画笔设置 nose(-100,100) #鼻子 head(-69,167) #头 ears(0,160) #耳朵 eyes(0,140) #眼睛 cheek(80,10) #腮 mouth(-20,30) #嘴 done() if __name__ == '__main__': main()
The idea is actually very simple, which is to realize basic circles, ellipses, curves, etc. through the trutle module. The difficulty lies in how to locate the position of each part (it is recommended to sketch the drawing first) painting).
The above is the complete introduction. I hope you can gain something. For more Python video tutorials, please pay attention to the PHP Chinese website.
The above is the detailed content of What is Page, Python tells you!. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.
