How to draw a pig head with python: first set the canvas and brush, the code is [a.screensize(400,300)a.setup(width=400,height=300)]; then draw the face shape, the code is [. goto(-100,100)]; Finally, just save the image on the canvas.
【Related learning recommendations: python video】
How to draw a pig head with python:
Canvas and brush settings
import turtle as a a.screensize(400,300)//设置屏幕大小 a.setup(width=400,height=300)//设置画布大小 a.pensize(15)//设置画笔宽度 a.speed(5)//设置画笔速度 a.hideturtle()//隐藏画笔
Drawing face plate
a.penup()//提笔 a.goto(-100,100)//移动画笔位置 a.setheading(180)//设置朝向正西 a.pencolor("pink") a.pendown()//放笔 a.circle(200)
Name
a.penup()//取名 a.goto(-150,10) yourname=a.textinput("请老实回答","你的名字是?") name=yourname+"崽崽" a.pendown() a.write(name,font=("elephant",25,"bold"))//打印文本
Draw the eyes
a.penup()//画左眼 a.goto(-200,0) a.pendown() a.circle(25) a.penup() a.goto(-200,-14) a.pendown() a.circle(9) a.penup()//光晕 a.goto(-190,-20) a.pencolor("white") a.pendown() a.dot(10) a.penup()//画右眼 a.pencolor("pink") a.goto(0,0) a.pendown() a.circle(25) a.penup()//光晕 a.goto(0,-14) a.pendown() a.circle(9) a.penup() a.goto(-10,-20) a.pencolor("white") a.pendown() a.dot(10)
Draw the nose
a.penup()//画鼻子 a.speed(10)//设置画笔速度 a.pencolor("pink") a.goto(-150,-75) a.setheading(45) a.pendown() for i in range(90): a.forward(1.5) a.right(1) for i in range(3): //圆化棱角,每转16度向前走3个像素 a.right(16) a.forward(3) a.forward(15) for i in range(3): //圆化棱角 a.right(16) a.forward(3) a.setheading(225) for i in range(90): a.forward(1.5) a.right(1) for i in range(3): //圆化棱角 a.right(16) a.forward(3) a.forward(15) for i in range(3): //圆化棱角 a.right(16) a.forward(3) a.penup() a.speed(5)//设置画笔速度 a.goto(-125,-70)//第一条杠 a.setheading(270) a.pendown() a.forward(50) a.penup() a.goto(-70,-65)//第二条杠 a.pendown() a.forward(55)
Draw the mouth
a.penup()//画嘴巴 a.speed(10)//设置画笔速度 a.goto(-135,-165) a.setheading(305) a.pendown() for i in range(120): a.forward(1) a.left(1)
Draw the ears
a.penup()//画右耳朵 a.speed(5) a.setheading(0) a.goto(-17,90) a.pendown() a.forward(60) a.penup() a.goto(28,75)//跳到下一笔起始位置 a.setheading(45) a.pendown() a.forward(110) a.right(45) a.forward(40) a.setheading(225) a.forward(40) a.setheading(270) for i in range(7): //圆化棱角 a.right(2.5) a.forward(10) a.forward(80) a.penup()//画左耳朵 a.goto(-183,90) a.setheading(180) a.pendown() a.forward(60) a.penup() a.goto(-230,75)//跳到下一笔起始位置 a.setheading(135) a.pendown() a.forward(110) a.left(45) a.forward(40) a.setheading(-45) a.forward(40) a.setheading(270) for i in range(10): //圆化棱角 a.left(2.5) a.forward(15)
Draw the blush
a.penup()//画左腮红 a.pencolor("tomato")//设置成番茄色 a.goto(-250,-100) a.setheading(270) a.pendown() a.forward(20) a.penup() a.goto(-210,-100) a.pendown() a.forward(20) a.penup()//画右腮红 a.goto(10,-100) a.pendown() a.forward(20) a.penup() a.goto(50,-100) a.pendown() a.forward(20)
a.done() //留存图像在画布上
Present the complete source code
#!/usr/bin/env python3.7 #指明用什么可执行程序运行这个文件代码 #-*- coding:UTF-8 -*- #保证能顺利解析中文 #author:Boosirit time:2020/4/5 import turtle as a a.screensize(400,300)#设置屏幕大小 a.setup(width=400,height=300)#设置画布大小 a.pensize(15)#设置画笔宽度 a.speed(5)#设置画笔速度 a.hideturtle()#隐藏画笔 a.penup()#画脸 a.goto(-100,100) a.setheading(180)#设置朝向正西 a.pencolor("pink") a.pendown() a.circle(200) a.penup()#取名 a.goto(-150,10) yourname=a.textinput("请老实回答","你的名字是?") name=yourname+"崽崽" a.pendown() a.write(name,font=("elephant",25,"bold"))#打印文本 a.penup()#画左眼 a.goto(-200,0) a.pendown() a.circle(25) a.penup() a.goto(-200,-14) a.pendown() a.circle(9) a.penup()#光晕 a.goto(-190,-20) a.pencolor("white") a.pendown() a.dot(10) a.penup()#画右眼 a.pencolor("pink") a.goto(0,0) a.pendown() a.circle(25) a.penup()#光晕 a.goto(0,-14) a.pendown() a.circle(9) a.penup() a.goto(-10,-20) a.pencolor("white") a.pendown() a.dot(10) a.penup()#画鼻子 a.speed(10)#设置画笔速度 a.pencolor("pink") a.goto(-150,-75) a.setheading(45) a.pendown() for i in range(90): a.forward(1.5) a.right(1) for i in range(3):#圆化棱角,每转16度向前走3个像素 a.right(16) a.forward(3) a.forward(15) for i in range(3):#圆化棱角 a.right(16) a.forward(3) a.setheading(225) for i in range(90): a.forward(1.5) a.right(1) for i in range(3):#圆化棱角 a.right(16) a.forward(3) a.forward(15) for i in range(3):#圆化棱角 a.right(16) a.forward(3) a.penup() a.speed(5)#设置画笔速度 a.goto(-125,-70)#第一条杠 a.setheading(270) a.pendown() a.forward(50) a.penup() a.goto(-70,-65)#第二条杠 a.pendown() a.forward(55) a.penup()#画嘴巴 a.speed(10)#设置画笔速度 a.goto(-135,-165) a.setheading(305) a.pendown() for i in range(120): a.forward(1) a.left(1) a.penup()#画右耳朵 a.speed(5) a.setheading(0) a.goto(-17,90) a.pendown() a.forward(60) a.penup() a.goto(28,75)#跳到下一笔起始位置 a.setheading(45) a.pendown() a.forward(110) a.right(45) a.forward(40) a.setheading(225) a.forward(40) a.setheading(270) for i in range(7):#圆化棱角 a.right(2.5) a.forward(10) a.forward(80) a.penup()#画左耳朵 a.goto(-183,90) a.setheading(180) a.pendown() a.forward(60) a.penup() a.goto(-230,75)#跳到下一笔起始位置 a.setheading(135) a.pendown() a.forward(110) a.left(45) a.forward(40) a.setheading(-45) a.forward(40) a.setheading(270) for i in range(10):#圆化棱角 a.left(2.5) a.forward(15) a.penup()#画左腮红 a.pencolor("tomato")#设置成番茄色 a.goto(-250,-100) a.setheading(270) a.pendown() a.forward(20) a.penup() a.goto(-210,-100) a.pendown() a.forward(20) a.penup()#画右腮红 a.goto(10,-100) a.pendown() a.forward(20) a.penup() a.goto(50,-100) a.pendown() a.forward(20) a.done()#留存图像在画布上
If you want to know more about programming learning, please pay attention to the php training column!
The above is the detailed content of How to draw a pig head using python. For more information, please follow other related articles on the PHP Chinese website!

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

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.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.