[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Rect's real width and height



On Thu, Sep 13, 2001 at 11:35:51AM +0200, Ludek Smid wrote:
> I think, there is something wrong...
> 
>  >>> from pygame.locals import *
>  >>> r = Rect(10, 10, 10, 10)
>  >>> r
> <rect(10, 10, 10, 10)>
>  >>> r.topleft
> (10, 10)
>  >>> r.bottomright
> (20, 20)
> 
> (The same is for all other rect's methods returning coordinates)
> 
> Hey, this rect is actually 11 points width and 11 points height. Am I 
> missing something?
Yes.
Actually.. the rect is 10 points wide and 10 points high. Just as you
specified it.
A rect is created with these 4 values:
Rect(left, top, width, height)
So when you pass 10 to width and height the height and width will be 10
not 11 (sounds somewhat logical huh? :)

The r.topleft is giving you the coordinates of the top left corner of
the rectangle in absolute coordinates. So whatever you specify for the
rect creation (in your example 10,10) is the result of the topleft.
The bottomright is again the absolute coordinate of the bottom right
corner thus it is the result from topleft plus width,height. 
I'll include another small example with slightly different values which
might help you to understand this:

>>> r = Rect(2,5,30,40)
>>> r.topleft; r.bottomright
(2, 5)
(32, 45)

Now r is a rectangle which is situated between (2,5) and (32,45) having
a width of 30 and a height of 40.

HTH,
-- 
Raiser, Frank aka CrashChaos
IRC: 141.30.225.9:6667 #United-Programmers

Just say NO to useless features     Just say NO to high priced bloatware
Just say NO to invasion of privacy  Just say NO to Microsoft Windows XP
And remember, friends don't let friends use Windows XP!
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org