I found the following code on Open Processing.
https://www.openprocessing.org/sketch/374455
Would somebody help me understand the Particle class? In particular, what is the math going on in the update
function?
class Particle{
PVector pos, vel;
float saturation;
Particle(){
float posAng = random(TWO_PI);
float posSize = random(maxRadious);
pos = new PVector(posSize * cos(posAng), posSize * sin(posAng));
float velAng = random(TWO_PI);
float velSize = random(minVel, maxVel);
vel = new PVector(velSize * cos(velAng), velSize * sin(velAng));
saturation = random(100);
}
void update(){
pos.add(vel);
if(pos.mag() > maxRadious){
pos.limit(maxRadious);
float posAng = atan2(pos.y, pos.x);
float velAng = atan2(vel.y, vel.x);
float velSize = vel.mag();
vel.x = velSize * cos(2 * posAng - velAng - PI);
vel.y = velSize * sin(2 * posAng - velAng - PI);
}
}
}