当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python turtle.get_shapepoly()用法及代码示例


turtle 模块以面向对象和面向过程的方式提供 turtle 图形基元。由于它使用Tkinter作为基础图形,因此需要安装有Tk支持的Python版本。

turtle .get_shapepoly()

此方法用于将当前形状多边形作为坐标对元组返回。它不需要任何参数。

用法:

turtle.get_shapepoly()

下面是上述方法的实现和一些示例:

范例1:



Python3

# 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:

Python3

# 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))

相关用法


注:本文由纯净天空筛选整理自deepanshu_rustagi大神的英文原创作品 turtle.get_shapepoly() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。