Inspiration
30-minute youtube videos showing off other physics engines and CSE 450A, insofar that working in Unity and on games has a similar loop of update --> render. Also, we just thought it would be neat!
What it does
Currently it is basic physics engine with static and dynamic objects, i.e., walls and balls/particles. The latter can undergo inelastic or elastic collision with static or other dynamic objects, respectively. Each demo we've prepared is rendered in real-time on the Raspberry Pi Zero and displayed on the UnicornHATHD. Our main function cycles through our progression, from displaying a single pixel to simulating a ball bouncing off multiple surfaces.
How we built it
We used OOP to create objects, a scene, and a collision handler to handle object interaction. All code is in Python. The only packages we used were Numpy, the UnicornHATHD API (the text scroll is pulled from here, all credit to them), and FastLine, a small repo we use to calculate vector intersections for collision detection. In other words, we built the engine from (nearly) scratch, developing algorithms and rendering solutions ourselves with minimal influence from the web.
Challenges we ran into
Rendering physics demos on a 16x16 pixel board proved more difficult than we had originally thought. A lot of trouble came from being forced to render in only integers -- not floats, which is not entirely conducive to physics calculations. The collision detection was also a real pain, in part again due to the strict constraint to integers, and trade-offs between accuracy and computational efficiency. For instance, in trying to handle simultaneous collisions, we developed an O(n!) algorithm; needless to say, there's no way a Raspberry Pi Zero can handle that.
Accomplishments that we're proud of
Due to the relatively niche nature of our project, running a physics engine but also rendering it on a HAT, meant that we had to rely on our own knowledge and could not Google as much as a software dev would like. The fact that the thing works at all, and to the level it does, after only, essentially, a day of work is extremely gratifying.
What we learned
Python, believe it or not, is not a great language for low-level computations and simulation! Go figure. Also, rendering things is hard — and rendering them on LED pixels is even harder.
What's next for Python Physics Engine
Expanding the type of objects available and environments for them to interact in, e.g., different gravities, frictions, and more. Improving the runtime complexity of the simulation so it can handle more interacting bodies and render them smoother. Taking further advantage of the UnicornHD's color options and different smoothing algorithms to improve the quality of rendered animations.
Built With
- python
- unicornhd
Log in or sign up for Devpost to join the conversation.