Classes and Arrays

Sharing (Classes) is Caring

Part of the concept of code is that it’s modular. Blocks of code should be reusable and pass-around-able.

In this week’s assignment, Nick and I independently created classes of objects and shared them with each other. In this post I’ll show you my class, in the next one I’ll try and break down Nick’s and then show you how the two did or didn’t mesh.


I created a simple particle class that changes its fill to a random color when it hits a boundary. You can check the code here. (Working with git through the terminal was another mini project unto itself. But I’m getting way more comfortable navigating and using git. It’s starting to stick.)

I was keeping the object simple this week in order to add layers of complexity in the way the code was written (i.e. creating classes and an array of objects). The initial idea was to create particles that bounced off walls and each other, changing to a random color when they hit a wall, and passing a color on when they collided with each other. I thought that visually it might be interesting and create a swarm-looking system without the more complex physics simulation code. The color transfer would be enough information that the objects would look like they where somehow connected.

I wasn’t able to crack the collision/color exchange. But that’s a definite next step.

I had a ton of trouble with the acceleration variables. I couldn’t get it to work properly without being sort of self-relegated to one quadrant of the window (as you can see in the video below, which I was used for visual de-bugging). Or quickly ramping up to an infinite speed.

For the sake of my sanity I decided to drop acceleration all together and just work with a velocity for the particles.