Python turtle库的使用
直接打开Python app,出现命令行
turtle.home() 打开面板
turtle.position() 查看当前位置
turtle.heading() 查看当前方向
https://docs.python.org/3/library/turtle.html
https://docs.python.org/3/library/turtle.html#turtle.circle
turtle.
circle
(radius, extent=None, steps=None)-
- Parameters
-
-
radius – a number
-
extent – a number (or
None
) -
steps – an integer (or
None
)
-
Draw a circle with given radius. The center is radius units left of the turtle; extent – an angle – determines which part of the circle is drawn. If extent is not given, draw the entire circle. If extent is not a full circle, one endpoint of the arc is the current pen position.
Draw the arc in counterclockwise逆时针方向 direction if radius is positive, otherwise in clockwise顺时针方向 direction.
Finally the direction of the turtle is changed by the amount of extent.
As the circle is approximated by an inscribed regular polygon, steps determines the number of steps to use. If not given, it will be calculated automatically. May be used to draw regular polygons.
>>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0 >>> turtle.circle(50) >>> turtle.position() (-0.00,0.00) >>> turtle.heading() 0.0 >>> turtle.circle(120, 180) # draw a semicircle >>> turtle.position() (0.00,240.00) >>> turtle.heading() 180.0
https://docs.python.org/3/library/turtle.html#turtle.setheading
turtle.
setheading
(to_angle)turtle.
seth
(to_angle)-
- Parameters
-
to_angle – a number (integer or float)
Set the orientation of the turtle to to_angle. Here are some common directions in degrees:
standard mode
logo mode
0 - east
0 - north
90 - north
90 - east
180 - west
180 - south
270 - south
270 - west
>>> turtle.setheading(90) >>> turtle.heading() 90.0
up和down函数,分别是提笔和落笔
https://docs.python.org/3/library/turtle.html#turtle.goto
goto 和 setpos是同一个作用
https://docs.python.org/3/library/turtle.html#turtle.pencolor
turtle.
pencolor
(*args)-
Return or set the pencolor.
Four input formats are allowed:
pencolor()
-
Return the current pencolor as color specification string or as a tuple (see example). May be used as input to another color/pencolor/fillcolor call.
pencolor(colorstring)
-
Set pencolor to colorstring, which is a Tk color specification string, such as
"red"
,"yellow"
, or"#33cc8c"
. pencolor((r, g, b))
-
Set pencolor to the RGB color represented by the tuple of r, g, and b. Each of r, g, and b must be in the range 0..colormode, where colormode is either 1.0 or 255 (see
colormode()
). pencolor(r, g, b)
-
Set pencolor to the RGB color represented by r, g, and b. Each of r, g, and b must be in the range 0..colormode.
If turtleshape is a polygon, the outline of that polygon is drawn with the newly set pencolor.
>>> colormode() 1.0 >>> turtle.pencolor() 'red' >>> turtle.pencolor("brown") >>> turtle.pencolor() 'brown' >>> tup = (0.2, 0.8, 0.55) >>> turtle.pencolor(tup) >>> turtle.pencolor() (0.2, 0.8, 0.5490196078431373) >>> colormode(255) >>> turtle.pencolor() (51.0, 204.0, 140.0) >>> turtle.pencolor('#32c18f') >>> turtle.pencolor() (50.0, 193.0, 143.0)
>>> tup = (0.2, 0.8, 0.55)
>>> type(tup)
<class 'tuple'>
- Parameters
-
speed – an integer in the range 0..10 or a speedstring (see below)
Set the turtle’s speed to an integer value in the range 0..10. If no argument is given, return current speed.
If input is a number greater than 10 or smaller than 0.5, speed is set to 0. Speedstrings are mapped to speedvalues as follows:
-
“fastest”: 0
-
“fast”: 10
-
“normal”: 6
-
“slow”: 3
-
“slowest”: 1
Speeds from 1 to 10 enforce increasingly faster animation of line drawing and turtle turning.
Attention: speed = 0 means that no animation takes place. forward/back makes turtle jump and likewise left/right make the turtle turn instantly.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2021-09-17 向量内积(点乘)和外积(叉乘)概念及几何意义
2021-09-17 jQuery Migrate
2021-09-17 Best way to expose resource strings to JavaScript files in ASP.NET MVC?
2021-09-17 What's the difference between sweetalert and sweetalert2?
2021-09-17 Does javascript have an Equivalent to C#s HttpUtility.HtmlEncode? [duplicate]
2021-09-17 sweetalert2 and xss
2021-09-17 上海居住证办理条件以及流程?