当前位置:网站首页>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()
边栏推荐
- Cross domain and jsonp details
- Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
- HotSpot VM
- 食品行业仓储条码管理系统解决方案
- Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
- Basic use of MySQL (it is recommended to read and recite the content)
- CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
- 【HBZ分享】ArrayList的增删慢查询快的原因
- 729. My schedule I (set or dynamic open point segment tree)
- Lambda expression learning
猜你喜欢
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
Execution order of scripts bound to game objects
1291_Xshell日志中增加时间戳的功能
Coreldraw2022 new version new function introduction cdr2022
About some basic DP -- those things about coins (the basic introduction of DP)
Meet diverse needs: jetmade creates three one-stop development packages to help efficient development
VNCTF2022 WriteUp
One question per day (Mathematics)
Slow SQL fetching and analysis of MySQL database
Web components series (VII) -- life cycle of custom components
随机推荐
Mysql数据库慢sql抓取与分析
VPP performance test
2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
How many of the 10 most common examples of istio traffic management do you know?
Lagrange polynomial
捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
1008 circular right shift of array elements (20 points)
Recommendation system (IX) PNN model (product based neural networks)
729. 我的日程安排表 I(set or 动态开点线段树)
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
[face recognition series] | realize automatic makeup
coreldraw2022新版本新功能介绍cdr2022
2327. 知道秘密的人数(递推)
[HBZ share] reasons for slow addition and deletion of ArrayList and fast query
[disassembly] a visual air fryer. By the way, analyze the internal circuit
After learning classes and objects, I wrote a date class
Lombok原理和同时使⽤@Data和@Builder 的坑
Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
CertBot 更新证书失败解决
Solve the compilation problem of "c2001: line breaks in constants"