Home  >  Article  >  Backend Development  >  What is Page, Python tells you!

What is Page, Python tells you!

云罗郡主
云罗郡主Original
2019-01-21 10:35:301583browse

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!

What is Page, Python tells you!

#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__ == &#39;__main__&#39;:
    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).

What is Page, Python tells you!

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is PythonNext article:What is Python