Home > Backend Development > Python Tutorial > Use turtle to draw a single dog and give it to yourself~

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

coldplay.xixi
Release: 2020-11-11 17:15:41
forward
2688 people have browsed it

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()复制代码
Copy after login
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!

Related labels:
source:juejin.im
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template