search
HomeBackend DevelopmentPython TutorialUse turtle to draw a single dog and give it to yourself~

python video tutorial column introduces how to use turtle to draw pictures.

Use turtle to draw a single dog and give it to yourself~

This year’s Double Eleven is here

But who else remembers that Double Eleven is a holiday for singles

##It’s time for me to stand up as a single person

It’s time to defend my rights

I am single What kind of state? All of us have been single, but perhaps only a few of us have truly experienced it.

The short video content is completely fake. The whole process is operated by one person. You must have a good mobile phone and a good copywriting idea.

Turtle

The Turtle library is a very popular function library for drawing images in the Python language. Imagine a little turtle in a coordinate system with the horizontal axis as x and the vertical axis as y. , starting from the origin (0,0) position, it moves in this plane coordinate system according to a set of function instructions, thereby drawing graphics on the path it crawls.

Turtle function

There are many functions for manipulating turtle drawing. These functions can be divided into three types: one is the brush control function, one is the motion control function, and the other is the direction control. function.

Brush control function

##Function nameturtle.penup()turtle.pendown()turtle.pencolor()turtle.pensize()Motion control function
Function
Raise the brush and stop painting
Put down the brush and start painting, the first two Appears in pairs
Painting color
Brush thickness

##Function nameFunctionturtle.forward(d)Move forward, walk in a straight line, d can be negativeturtle .circle(r,extent=None)Draw an arc with an extent angle using r as the radius. The extent can be omitted and a full circle is drawn by default. If r is positive, it is drawn to the left of the forward direction, and if it is negative, it is drawn to the right. Direction control function

Function nameFunctionturtle.setheading(angle)Change the direction of travel, but not travel, it is an absolute angleturtle.left(angel )The turtle turns left, the angle of angel's rotation in the current direction of travel of the turtleturtle.right(angel)The turtle turns right , the angle of angel's rotation in the current direction of travel of the turtlePainting Single Dog
import turtle as t
t.screensize(500, 500)# 【头部轮廓】t.pensize(5)
t.home()
t.seth(0)
t.pd()  #pendownt.color('black')
t.circle(20, 80)  # 0t.circle(200, 30)  # 1t.circle(30, 60)  # 2t.circle(200, 29.5)  # 3t.color('black')
t.circle(20, 60)  # 4t.circle(-150, 22)  # 5t.circle(-50, 10)  # 6t.circle(50, 70)  # 7# 确定鼻头大概位置 t.xcor和t.ycor乌龟一开始的位置x_nose = t.xcor()
y_nose = t.ycor()
t.circle(30, 62)  # 8t.circle(200, 15)  # 9# 【鼻子】t.pu() #penupt.goto(x_nose, y_nose + 25)
t.seth(90)
t.pd()
t.begin_fill()
t.circle(8)
t.end_fill()# 【眼睛】t.pu()
t.goto(x_nose + 48, y_nose + 55)
t.seth(90)
t.pd()
t.begin_fill()
t.circle(8)
t.end_fill()# 【耳朵】t.pu()
t.color('#444444')
t.goto(x_nose + 100, y_nose + 110)
t.seth(182)
t.pd()
t.circle(15, 45) 
t.color('black')
t.circle(10, 15)  
t.circle(90, 70)  
t.circle(25, 110)  
t.rt(4)
t.circle(90, 70)  
t.circle(10, 15)  
t.color('#444444')
t.circle(15, 45) 
# 【身体】t.pu()
t.color('black')
t.goto(x_nose + 90, y_nose - 30)
t.seth(-130)
t.pd()
t.circle(250, 28)  
t.circle(10, 140)  
t.circle(-250, 25)  
t.circle(-200, 25)  
t.circle(-50, 85)  
t.circle(8, 145)  
t.circle(90, 45)
t.circle(550, 5)  
# 【尾巴】t.seth(0)
t.circle(60, 85) 
t.circle(40, 65) 
t.circle(40, 60)  
t.lt(150)  #leftt.circle(-40, 90)  
t.circle(-25, 100)  
t.lt(5)
t.fd(20)
t.circle(10, 60)  
# 【背部】t.rt(80)  #rightt.circle(200, 35)# 【项圈】t.pensize(20)
t.color('#F03C3F')
t.lt(10)
t.circle(-200, 25)  
# 【爱心铃铛】t.pu()
t.fd(18)
t.lt(90)
t.fd(18)
t.pensize(6)
t.seth(35)  #setheadingt.color('#FDAF17')
t.begin_fill()
t.lt(135)
t.fd(6)
t.right(180)  # 画笔掉头t.circle(6, -180)
t.backward(8)
t.right(90)
t.forward(6)
t.circle(-6, 180)
t.fd(15)
t.end_fill()# 【前小腿】t.pensize(5)
t.pu()
t.color('black')
t.goto(x_nose + 100, y_nose - 125)
t.pd()
t.seth(-50)
t.fd(25)
t.circle(10, 150)
t.fd(25)# 【后小腿】t.pensize(4)
t.pu()
t.goto(x_nose + 314, y_nose - 125)
t.pd()
t.seth(-95)
t.fd(25)
t.circle(-5, 150)
t.fd(2)
t.hideturtle()
t.done()复制代码
The results obtained are as follows:

Related free learning recommendations:

python video tutorial

The above is the detailed content of Use turtle to draw a single dog and give it to yourself~. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:juejin. If there is any infringement, please contact admin@php.cn delete
Python: Automation, Scripting, and Task ManagementPython: Automation, Scripting, and Task ManagementApr 16, 2025 am 12:14 AM

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

Python and Time: Making the Most of Your Study TimePython and Time: Making the Most of Your Study TimeApr 14, 2025 am 12:02 AM

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python: Games, GUIs, and MorePython: Games, GUIs, and MoreApr 13, 2025 am 12:14 AM

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python vs. C  : Applications and Use Cases ComparedPython vs. C : Applications and Use Cases ComparedApr 12, 2025 am 12:01 AM

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

The 2-Hour Python Plan: A Realistic ApproachThe 2-Hour Python Plan: A Realistic ApproachApr 11, 2025 am 12:04 AM

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python: Exploring Its Primary ApplicationsPython: Exploring Its Primary ApplicationsApr 10, 2025 am 09:41 AM

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

How Much Python Can You Learn in 2 Hours?How Much Python Can You Learn in 2 Hours?Apr 09, 2025 pm 04:33 PM

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics in project and problem-driven methods within 10 hours?How to teach computer novice programming basics in project and problem-driven methods within 10 hours?Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

DVWA

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

Safe Exam Browser

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!