[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Native PyGame method for automatically scaling inputs to a surface resolution?



Yeah short answer no. However, I think the answers you've gotten from StackOverflow have not been terribly helpful. They seem to suggest "don't do scaling in pygame". This is silly, I do scaling in pygame all the time. There's no reason you'd need to work in screen coordinates.

I use wrappers. Let me point out there's a total of 9 functions in pygame.draw. You seem to be going to a lot of effort to avoid writing 9 one-line functions. (And I usually only ever use about 3 or 4 in any one application.) Writing the wrappers is the best way, and I don't think you should have dismissed it so quickly.

Since this is a very common problem, I wonder if there is an established pattern that elegantly solves this problem that I failed to find.

I don't consider the wrappers that inelegant. However, you could also do it pretty easily with a function decorator if that's preferable for you....

I could simply decorate the existing middleware functions, but the problem is that those functions also work with the same parameters being list or Vector2D too, and the decorator would have no way to know which lists need to be scaled (the radius for example) and which not (the RGB values).

With one example, everything numerical should be scaled except for RGB values. Since these are always the second argument to the function, it should be trivial to accept the first two arguments (surf and color) and scale everything else as needed. The only other exception is the angles in pygame.draw.arc. So you would have to write one special case, assuming you actually need pygame.draw.arc.

I hope you find a solution that satisfies you. It's not that there aren't plenty of solutions! :)

-Christopher

On Fri, Sep 23, 2011 at 4:29 AM, Mac Ryan <quasipedia@xxxxxxxxx> wrote:
Hello,

       back July, I posted a question on StackOverflow titled that so
far still did not get any answer. So - although I believe the answer is
quite simply "NO" - I thought to repost it here:

----------------

In my program (which uses pygame to draw objects on the video) I have
two representation of my world:

- A physical one that I use to make all the calculations involved in the
 simulation and in which objects are located on a 1000x1000 metres
 surface.
- A visual one which I use to draw on the screen, in which my objects
 are located in a window measuring 100x100 pixels.

What I want to achieve is to be able to pass to my pygame drawing
functions (which normally accept inputs in pixels) my
physical/real-word coordinates. In other words, I would like to be able
to say:

Draw a 20m radius circle at coordinates (200m, 500m)
using the precise pygame syntax:

pygame.draw.circle(surface, (255,255,255), (200,500), 20)
and get my circle of 2px radius at centred on pixels (20,50).

----------------

If you are on SO and would like to answer there [too], I'll be happy to
dispense upvotes! ;) http://stackoverflow.com/q/6807459/146792