Skip to content

Instantly share code, notes, and snippets.

@brendandawes
Last active April 16, 2018 13:10
Show Gist options
  • Save brendandawes/8273dd418c8886e244afcff2a9c5d5aa to your computer and use it in GitHub Desktop.
Save brendandawes/8273dd418c8886e244afcff2a9c5d5aa to your computer and use it in GitHub Desktop.
Processing:Particle Class
class Node {
private PVector vel;
private PVector loc;
private PVector acc;
Node () {
vel = PVector.random2D();
loc = new PVector(random(width), random(height));
acc = PVector.random2D();
}
void update(){
vel.add(acc);
loc.add(vel);
acc.mult(0);
}
void applyForce(PVector force){
acc.add(force);
}
void checkEdges(){
if (loc.x >= width || loc.x <= 0) {
vel.x *=-1;
}
if (loc.y > height || loc.y < 0) {
vel.y *=-1;
}
}
void draw(){
strokeWeight(10);
stroke(0);
point(loc.x, loc.y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment