我在尋找最佳的方式來自動找到新的海龜繪圖的起始位置,以便它將以圖形窗口爲中心,而不管它的大小和形狀如何。海龜繪圖自動對中
到目前爲止,我已經開發了一個函數,用於檢查每個繪製元素的烏龜位置,以便爲左,右,上和下找到極端值,並且以這種方式查找圖片大小,並且可以在釋放我之前使用它來調整起始位置碼。這是例如簡單的形狀,與我的圖片尺寸檢測繪製的說:
from turtle import *
Lt=0
Rt=0
Top=0
Bottom=0
def chkPosition():
global Lt
global Rt
global Top
global Bottom
pos = position()
if(Lt>pos[0]):
Lt = pos[0]
if(Rt<pos[0]):
Rt= pos[0]
if(Top<pos[1]):
Top = pos[1]
if(Bottom>pos[1]):
Bottom = pos[1]
def drawShape(len,angles):
for i in range(angles):
chkPosition()
forward(len)
left(360/angles)
drawShape(80,12)
print(Lt,Rt,Top,Bottom)
print(Rt-Lt,Top-Bottom)
但是這一方法的工作看起來很笨拙的我,所以我想問更多的經驗龜程序員有沒有更好的辦法找到啓動烏龜圖紙的位置,使他們居中?
問候
使用幾何找到起始位置。 – furas