当前位置:网站首页>Basic explanation of turtle module - draw curve
Basic explanation of turtle module - draw curve
2022-07-06 04:26:00 【Michael. py】
stay 《Turtle Detailed explanation of module foundation - Draw a straight line 》 in , We have introduced how to import turtle Library and use turtle Library to draw straight line graphics . This article will continue turtle Library high-level usage , How to use turtle Draw curve graph .
1. The little turtle draws the same tangent circle
The characteristic of tangent circles is that each circle starts from the same place , It can be seen as finding a circle center on the left or right side of the little turtle , With r Rotate for radius 360°, The difference is that the radius of each rotation is different .
# Import turtle library
import turtle
# Set the window size and initial position
turtle.setup(700, 400, 200, 200)
# Set the brush thickness
turtle.pensize(4)
# Set brush color
turtle.pencolor("red")
# Rotate the brush to the right 90°
turtle.right(90)
# Bring up the brush
turtle.penup()
# Brush back 20px
turtle.fd(-20)
# The paintbrush falls
turtle.pendown()
# Return to zero in the forward direction
turtle.seth(0)
# Find a circle center on the left side of the turtle and draw a radius of 40px The circle of
turtle.circle(40)
# Find a circle center on the left side of the turtle and draw a radius of 60px The circle of
turtle.circle(60)
# Find a circle center on the right side of the turtle and draw a radius of 60px The circle of
turtle.circle(-60)
# Set the brush color to green
turtle.color("green")
# Find a circle center on the right side of the turtle and draw a radius of 40px The circle of
turtle.circle(-40)
# Find a circle center on the left side of the turtle and draw a radius of 80px The circle of
turtle.circle(80)
# Find a circle center on the right side of the turtle and draw a radius of 80px The circle of
turtle.circle(-80)
# Program end
turtle.done()
Relevant knowledge in the above procedures :
1)turtle.pensize() You can set the thickness of the brush , Fill in numbers in brackets ;
2)turtle.pencolor() You can set the brush color , Fill in the color library in brackets ;
3)turtle.penup() and turtle.down() They are lifting the brush and putting it down , When the brush is lifted, the movement will not leave traces on the canvas ;
4)turtle.seth() Only change the direction of the turtle ( The angle is counterclockwise ), But don't move forward , Angle in brackets ;
5)turtle.circle(radius, extent, steps) You can draw a circle , The first parameter radius It's the radius of the circle , It could be negative , The starting coordinate of the brush is (0, 0), The coordinates of the center of the circle are (0, radius); The second parameter extent Is the size of the center angle , It can also be negative ; The third parameter steps It's the step length , Indicates that the starting point to the end point is composed of several lines , The greater the numerical , The rounder the circle is drawn .
2. Little turtle draws a curve
Conventional curves can be understood as circular segments , Use loops and circles to , Draw a curve on the screen .
# Import turtle library
import turtle
# Set the window size and initial position
turtle.setup(650, 350, 200, 200)
# Bring up the brush
turtle.penup()
# Brush back 20px
turtle.fd(-250)
# The paintbrush falls
turtle.pendown()
# The brush thickness is set to 15
turtle.pensize(15)
# Brush color is blue
turtle.pencolor("blue")
# The way forward is -40°
turtle.seth(-40)
# Use for Cycle draw waves
for i in range(4):
turtle.circle(40, 80)
turtle.circle(-40, 80)
turtle.circle(40, 80 / 2)
# Brush forward 40
turtle.fd(40)
# A circle
turtle.circle(16, 180)
# Brush forward
turtle.fd(40 * 2 / 3)
# Program end
turtle.done()
边栏推荐
- Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- 2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
- NPM command -- install dependent packages -- Usage / explanation
- newton interpolation
- Unity中几个重要类
- The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
- IDEA编译JSP页面生成的class文件路径
- hashlimit速率控制
- CertBot 更新证书失败解决
猜你喜欢
How does computer nail adjust sound
Comprehensive ability evaluation system
颠覆你的认知?get和post请求的本质
Coreldraw2022 new version new function introduction cdr2022
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
The value of two date types is subtracted and converted to seconds
Mlapi series - 04 - network variables and network serialization [network synchronization]
Web components series (VII) -- life cycle of custom components
View workflow
1291_Xshell日志中增加时间戳的功能
随机推荐
NPM command -- install dependent packages -- Usage / explanation
1291_ Add timestamp function in xshell log
【HBZ分享】ArrayList的增删慢查询快的原因
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
CADD course learning (8) -- virtual screening of Compound Library
Solution to the problem that the root account of MySQL database cannot be logged in remotely
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
Easyrecovery reliable and toll free data recovery computer software
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
MySql數據庫root賬戶無法遠程登陸解决辦法
Coreldraw2022 new version new function introduction cdr2022
Knowledge consolidation source code implementation 3: buffer ringbuffer
Solution of storage bar code management system in food industry
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
Hashlimit rate control
2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
Fedora/REHL 安装 semanage
Yyds dry goods inventory web components series (VII) -- life cycle of custom components