Some Python Raylib Notes

Coordinates vs pixels

Since I’m interested in using raylib to visualize some computations, I want to almost exclusively deal with world coordinates (in, say, meters), and then only at the end (when drawing to the screen) convert to screen coordinates (in pixels).

For example, suppose I want:

When my code for solving real-world problems generates x and y values in meters, I want to convert those “world coords” (meters) into “screen coords” (pixels) so I can draw things to the screen. If we use subscripts “w” to mean world, and “s” to mean screen, and just put in \(C_{1}\) and \(C_{2}\) to stand-in for the conversion factors between screen (pixels) and world (meters):

\[x_{\text{s}} = C_{1}x_{\text{w}}\]

\[y_{\text{s}} = -C_{2}y_{\text{w}} + h\]

where \(h\) is screen_height in pixels.

Here’s the code (“wo” means “world”, “sc” means “screen”):

see ~/temp/foo.py

Run it and see how the screen is “10 m wide” and “8 m tall”.