[Tutor] using rect.inflate()
srilyk at gmail.com
Thu Nov 6 12:11:26 CET 2008
On Wed, Nov 5, 2008 at 8:14 PM, John Fouhy <john at fouhy.net> wrote:
> 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?
IIRC - in pygame (and some of the other modules) they use a Q4 type
coordinate system. I *think* anyway - it's been a while.
But I believe they work from the top left corner, instead of bottom left. So
your XY rather than (2, 4) moving right and up moves right and down.
Similarly, any manipulations you make will also work from (0,0), rather than
(2, 4) like you might expect.
I'm not 100% sure on that, so you may want to research for a bit just to
either verify or disprove my dim memory of the possible situation.
> 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
> I'm not sure what's going on with the height, though.
> Tutor maillist - Tutor at python.org
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor