Colorful Particles
This week I developed a simple sketch using p5 basic shapes and some transform functions.
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
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.
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.