turtle 模塊以麵向對象和麵向過程的方式提供 turtle 圖形基元。由於它使用Tkinter作為基礎圖形,因此需要安裝有Tk支持的Python版本。
turtle .get_poly()
此函數用於返回最後記錄的多邊形。它不需要任何參數。
用法:
turtle.get_poly()
下麵是上述方法的實現示例:
例:製作多邊形並使用get_poly()方法
在此示例中,我們繪製一個橢圓並使用begin_poly()和end_poly()方法進行記錄。通過使用get_poly()方法,我們可以獲取多邊形的所有坐標,然後進行打印。我們也可以使用它來注冊形狀。
Python3
# import package
import turtle
# start recording polygon
turtle.begin_poly()
# form an ellipse
turtle.circle(20,90)
turtle.circle(10,90)
turtle.circle(20,90)
turtle.circle(10,90)
# end recording polygon
turtle.end_poly()
# get poly that recorded
print(turtle.get_poly())
輸出:
((0.00,0.00), (7.65,1.52), (14.14,5.86), (18.48,12.35), (20.00,20.00), (19.24,23.83), (17.07,27.07),
(13.83,29.24), (10.00,30.00), (2.35,28.48), (-4.14,24.14), (-8.48,17.65), (-10.00,10.00),
(-9.24,6.17), (-7.07,2.93), (-3.83,0.76), (0.00,0.00))
相關用法
- Python Wand function()用法及代碼示例
- Python str()用法及代碼示例
- Python oct()用法及代碼示例
- Python tell()用法及代碼示例
- Python cmp()用法及代碼示例
- Python dir()用法及代碼示例
- Python sum()用法及代碼示例
- Python ord()用法及代碼示例
- Python map()用法及代碼示例
- Python hex()用法及代碼示例
- Python int()用法及代碼示例
- Python id()用法及代碼示例
- Python now()用法及代碼示例
- Python strftime()用法及代碼示例
- Python Sorted()用法及代碼示例
- Python type()用法及代碼示例
- Python statistics mean()用法及代碼示例
注:本文由純淨天空篩選整理自deepanshu_rustagi大神的英文原創作品 turtle.get_poly() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。