MLNI – Colorful Particles (Billy Zou)

Colorful Particles

This week I developed a simple sketch using p5 basic shapes and some transform functions.

Colorful particles

Particle

I coded these particles using class syntax. Since circles and squares in this case have a lot of properties in common, I used an abstract class Particle to include the common properties.

Problems

I did not directly draw particles at point (x, y). What I did was using

translate method to change the origin point of the canvas and draw the particle on (0, 0). What’s more, I used rotate functions to rotate squares.

The problem I had was that translate function, once called, would permanently change the origin of the canvas. Therefore, I had to correct the origin every time a particle was drown. Also I had to rotate it back.
 

Remove particles

When particles are out of canvas and are invisible, we should remove them. I did not notice this problem at first. As a result, my webpage becomes laggy soon after the program started.

The solution was dynamically removing particles that were out of the canvas. Particles were stored in an array, so I could use some array methods to remove them. After I implemented this, the performance of my program was better.

Leave a Reply