Python中的turtle.get_shapepoly()函数
turtle模块以面向对象和面向过程的方式提供Turtle图形基元。因为它使用 Tkinter 作为底层图形,它需要安装一个支持 Tk 的 Python 版本。
turtle.get_shapepoly()
该方法用于返回当前形状的多边形,作为一个坐标对的元组。它不需要任何参数。
语法:
turtle.get_shapepoly()
下面是上述方法的实现和一些例子。
例子1 :
# import package
import turtle
# get default shape
print(turtle.shape())
# get default shapeploy
print(turtle.get_shapepoly())
# set some size
turtle.turtlesize(5, 5, 2)
# get default shapeploy
print(turtle.get_shapepoly())
输出 :
classic
((0, 0), (-5, -9), (0, -7), (5, -9))
((0.0, 0.0), (-25.0, -45.0), (0.0, -35.0), (25.0, -45.0))
例子2 :
# import package
import turtle
# get all shapes
shp=turtle.getshapes()
print(shp)
# loop for getting shapepoly
# of all the shapes
for i in range(len(shp)):
turtle.shape(shp[i])
print(turtle.get_shapepoly())
输出 :
[‘arrow’, ‘blank’, ‘circle’, ‘classic’, ‘square’, ‘triangle’, ‘turtle’]
((-10, 0), (10, 0), (0, 10))
None
((10, 0), (9.51, 3.09), (8.09, 5.88), (5.88, 8.09), (3.09, 9.51), (0, 10), (-3.09, 9.51), (-5.88, 8.09),
(-8.09, 5.88), (-9.51, 3.09), (-10, 0), (-9.51, -3.09), (-8.09, -5.88), (-5.88, -8.09), (-3.09, -9.51),
(-0.0, -10.0), (3.09, -9.51), (5.88, -8.09), (8.09, -5.88), (9.51, -3.09))
((0, 0), (-5, -9), (0, -7), (5, -9))
((10, -10), (10, 10), (-10, 10), (-10, -10))
((10, -5.77), (0, 11.55), (-10, -5.77))
((0, 16), (-2, 14), (-1, 10), (-4, 7), (-7, 9), (-9, 8), (-6, 5), (-7, 1), (-5, -3), (-8, -6), (-6, -8),
(-4, -5), (0, -7), (4, -5), (6, -8), (8, -6), (5, -3), (7, 1), (6, 5), (9, 8), (7, 9), (4, 7), (1, 10),
(2, 14))