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

AI Hentai Generator
Generate AI Hentai for free.

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

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

Alternative usage of Python parameter annotations In Python programming, parameter annotations are a very useful function that can help developers better understand and use functions...

Choice of Python Cross-platform desktop application development library Many Python developers want to develop desktop applications that can run on both Windows and Linux systems...

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

How do Python scripts clear output to cursor position at a specific location? When writing Python scripts, it is common to clear the previous output to the cursor position...

Getting started with Python: Hourglass Graphic Drawing and Input Verification This article will solve the variable definition problem encountered by a Python novice in the hourglass Graphic Drawing Program. Code...

Why can't my code get the data returned by the API? In programming, we often encounter the problem of returning null values when API calls, which is not only confusing...
