2014-01-23 37 views
-1

我目前正在使用python 2.7.5和pygame繪製程序。我遇到了橢圓工具的一個錯誤,並要求同學提供一些幫助,他說我錯過了.normalize()。我添加了它並且我的工具已修復。我現在只是想知道那個功能是幹什麼的。下面是它是在所使用的代碼:在Python中規範化函數

 if mb[0] == 1 and canvas.collidepoint(mx,my): 
     screen.set_clip(canvas) 
     if tool == "ellipse": 
      screen.blit(copy,(0,0)) 
      radius = Rect(startx,starty,mx-startx,my-starty) #Area Ellipse is being drawn 
      radius.normalize() 
     if radius.height<sz2*2 or radius.width<sz2*2: 
      draw.ellipse(screen,(c),(radius)) 
     else: 
      draw.ellipse(screen,(c),(radius), sz2) 
     screen.set_clip(None) 
+1

閱讀文檔:http://www.pygame.org/docs/ref/rect.html#pygame.Rect.normalize – jonrsharpe

+3

這個問題似乎是脫離主題,因爲它只是要求功能的文檔,任何合理的答案只是[這個鏈接](http://www.pygame.org/docs/ref/rect.html#pygame.Rect.normalize)。 – abarnert

回答

3

第一結果使用Google「pygame的矩形正常化」:

PyGame Rect Docs

normalize() 
correct negative sizes 
normalize() -> None 

這將翻轉,如果它的矩形的寬度或高度具有負尺寸。矩形將保留在相同的位置,只有兩面交換。

因此,本質上它確保了寬度和高度是正面的,而不是負面的。

+0

謝謝!我顯然不是在用google搜索正確的東西。 – user2950875