


How to draw a rabbit using Python - a detailed introduction to the use of the circle() circle drawing function in the turtle library
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.
The drawing effect is as shown in the figure:
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)
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.
Original 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()
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!

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.

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.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

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.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".
