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))
相關用法
- Python Wand function()用法及代碼示例
- Python tell()用法及代碼示例
- Python id()用法及代碼示例
- Python map()用法及代碼示例
- Python dir()用法及代碼示例
- Python cmp()用法及代碼示例
- Python int()用法及代碼示例
- Python ord()用法及代碼示例
- Python hex()用法及代碼示例
- Python now()用法及代碼示例
- Python oct()用法及代碼示例
- Python str()用法及代碼示例
- Python sum()用法及代碼示例
- Python seek()用法及代碼示例
- Python reversed()用法及代碼示例
注:本文由純淨天空篩選整理自deepanshu_rustagi大神的英文原創作品 turtle.get_shapepoly() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。