[Tutor] using rect.inflate()

John Fouhy john at fouhy.net
Thu Nov 6 03:14:08 CET 2008


2008/11/6 Christopher Spears <cspears2002 at yahoo.com>:
> I inserted this code snippet into the Spaceship class:
>
> self.rect = self.image.get_rect()
> print self.rect
> self.rect = self.rect.inflate(-50, -50)
> print self.rect
>
> The following was printed to my console:
> <rect<0, 0, 70, 53>>
> <rect<25, 25, 20, 37>>
>
> I'm assuming that the first two numbers are coordinates for the upper left corner of the rectangle.  The third and fourth numbers are the width and height of the rectangle from the upper left corner.  Am I off base here?
> If that is the case, why does rect.inflate() move the upper left corner?

At a guess: the inflation (or, in this case, deflation) is centred on
the centre of the figure.  So a horizontal change of -50 means the
left edge moves 25 pixels right and the right edge moves 25 pixels
left.  (or, rather, the total width drops frrom 70 pixels to 20
pixels)

I'm not sure what's going on with the height, though.

-- 
John.


More information about the Tutor mailing list