How to draw a pig head using python
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!

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.

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.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

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.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.
