This was a fun one. I took the opportunity to dive into some of Dan Shiffman’s work in Nature of Code. I modeled this sketch after his example’s: Flocking and Particles. It gave me the base for how to create objects and implement methods for control of those objects. The goal was to create a serene, space-like environment that acted sort of like an interactive screen saver.
The heart of the sketch is based around 3 classes – A System class, a Ball class, and a Wave class. The system class holds all the balls and waves as arrays, and the ball and wave classes control their own behavior (updating position, drawing, handling edge bounces, and collisions) though custom methods.
My biggest question has to do with handling collisions. I accomplished it like so:
Basically, for every frame we have to iterate through all the balls currently on screen. This could take too long if there are too many balls on screen. Thus slowing down the animation. I can induce this if I click like crazy, which isn’t really a problem, but it’s a bit annoying.