Question

I'm currently working on a paint program using python 2.7.5 and pygame. I came across an error with the ellipse tool and asked a classmate for some help and he said I was missing a .normalize(). I added it in and my tool was fixed. I'm currently just wondering what that function does. Here's the code it is used in:

        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)
Was it helpful?

Solution

First result googling "PyGame Rect Normalize":

PyGame Rect Docs

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

This will flip the width or height of a rectangle if it has a negative size. The rectangle will remain in the same place, with only the sides swapped.

So in essence it ensures the width and height are positive, not negative.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top