


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.

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.

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

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.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

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 is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.
