This question is related to this other one.
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 w开发者_JAVA技巧ould 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).
Please note that this question is about a native pygame way to do this, not some sort of workaround to achieve that result (if you want to answer that, you should take a look to the question I already mentioned) instead.
Thanks in advance for your time and support.
There is no native pygame way to do this.
You may be misunderstanding the function of pygame. It is not for drawing vector objects. It is for writing pixels into video surfaces.
Since you have vector objects, you must define how they will be converted into pixels. Doing this is not a workaround - it's how you are intended to use pygame.
Since it seems that PyGame developers do not hang around here too much, I brought the question to the Pygame mailing list where it originated a monster thread and the issue has been debated at large.
The summary would be:
- At present there is not such a feature.
- There is interest to implement it, or at least to try to implement it...
- ...although is not a priority of the core devs in any way
- There is more than one way to skin a cat:
- should be the scaling happen both ways (inputting coordinates and reading them)?
- how to deal with lines that have no thickness but that should be visible?
- how to deal with visibility of objects at the edge of the image? which of their points should be taken as reference to know if a pixel should be lit or not for them?
- and more (see linked thread).
精彩评论