Home > Backend Development > Python Tutorial > How to draw a rabbit using Python - a detailed introduction to the use of the circle() circle drawing function in the turtle library

How to draw a rabbit using Python - a detailed introduction to the use of the circle() circle drawing function in the turtle library

(*-*)浩
Release: 2019-08-02 16:16:13
forward
16372 people have browsed it

I studied the basic functions of the turtle library over the weekend and tried to draw a big-eared bunny. The inspiration came from the jellycat Bonnie rabbit. The circle() function in the turtle library is used to draw arcs, but it is different from the usual method of first determining the origin and then drawing the arc based on the radius and angle. After using it, you can understand the cleverness of the circle() function. The takeaway is: thinking and changing while doing is better than dreaming of perfection.

How to draw a rabbit using Python - a detailed introduction to the use of the circle() circle drawing function in the turtle library

The drawing effect is as shown in the figure:

How to draw a rabbit using Python - a detailed introduction to the use of the circle() circle drawing function in the turtle library

In circle(radius,extent ) function, the parameter radius takes the pixel value and extent takes the integer value of the angle. Both parameters can take positive and negative values. Run the following code to intuitively understand the drawing characteristics of the circle(radius,extent) function parameters when the parameters are positive and negative:

from turtle import *
pensize(5)
pencolor('green')
circle(100,90)
 
pu()
goto(0,0)
seth(0)
pd()
pencolor('orange')
circle(100,-90)
 
pu()
goto(0,0)
seth(0)
pd()
pencolor('blue')
circle(-100,90)
 
pu()
goto(0,0)
seth(0)
pd()
pencolor('red')
circle(-100,-90)
Copy after login

circle() function uses the current direction of the brush (y') as the y-axis direction, passing through The current absolute coordinates of the brush (x0, assuming y0=0), the direction perpendicular to the y-axis is the x-axis direction, then the coordinates of the center of the circle (i.e. the origin) are (x0-radius=0,0), and the current brush position (x0, y0 ) is the starting point of the arc, draw an arc with extent angle. In order to facilitate understanding, I drew the relative coordinate system of the circle() function, as shown below. It should be noted that when radius is positive, the center of the circle is to the left of the current position (as shown below); when radius is negative, the center of the circle is to the right of the current position; when extent is positive, draw in the current direction of the brush; when extent is negative, draw in the opposite direction. Draw in the current direction of the brush.

The above is my personal learning and understanding. I am new to turtle. Any corrections are welcome.

How to draw a rabbit using Python - a detailed introduction to the use of the circle() circle drawing function in the turtle libraryOriginal works, for learning purposes only, infringers should respect themselves!

#绘制大耳朵兔
from turtle import *
speed(10)
 
#小兔的面部
color('pink')
pensize(5)
circle(radius=100)#脸
 
#眼睛
pencolor('black')
#左眼
pu()
goto(-45,92)
pd()
begin_fill()
color((0,0,0),(0,0,0.1))
circle(radius=15)
#右眼
pu()
goto(45,92)
pd()
circle(radius=15)
end_fill()
 
#鼻子
pu()
goto(20,60)
color('pink')
pd()
begin_fill()
goto(-20,60)
goto(0,45)
goto(20,60)
end_fill()
 
#嘴
goto(0,45)
goto(0,40)
seth(-90)
circle(10,120)
pu()
goto(0,40)
seth(-90)
pd()
circle(-10,120)
 
 
#小兔的耳朵
#左耳
pu()
goto(-60,180)#
seth(200)
pd()
circle(radius=350,extent=90)
goto(-98,110)
#右耳
pu()
goto(60,180)#
seth(-20)
pd()
circle(radius=-350,extent=90)
goto(98,110)
 
#小兔的身体
pu()
goto(20,3)
seth(-25)
pd()
circle(radius=-250,extent=25)
circle(radius=-135,extent=260)
seth(50)
circle(radius=-250,extent=25)
 
##小兔的胳膊
#左臂
pu()
seth(180)
goto(-30,-3)
pd()
#小短胳膊
##circle(radius=270,extent=20)
##circle(radius=20,extent=190)
circle(radius=248,extent=30)
circle(radius=29,extent=185)
#右臂
pu()
seth(0)
goto(30,-3)
pd()
circle(radius=-248,extent=30)
circle(radius=-27,extent=184)
 
##小兔的脚
##左脚
pu()
goto(-162,-260)#
pd()
seth(0)
circle(radius=41)
#右脚
pu()
goto(164,-260)
pd()
circle(radius=41)
 
done()
Copy after login

The above is the detailed content of How to draw a rabbit using Python - a detailed introduction to the use of the circle() circle drawing function in the turtle library. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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