• Show Sketch
/** @peep sketchcode */
int NUM_PARTICLES = 1000;
Particle[] particles;
 
void setup() {
  size(400, 400);
  PVector centre = new PVector(width/2, height/2, 0);
  particles = new Particle[NUM_PARTICLES];  
  for (int i = 0; i < particles.length; i++) {
    particles[i] = new Particle(centre);
  }
}
 
void update() {
  for (int i = 0; i < particles.length; i++) {
    particles[i].update();
  }
}
 
void draw() {
  update();
  background(255);
  for (int i = 0; i < particles.length; i++) {
    PVector l = particles[i].location;
    ellipse(l.x, l.y, 10, 10);
    fill(random(0,255));
    PVector v = particles[i].velocity;
 
  }
}
 
class Particle {
  PVector location;
  PVector velocity;
  PVector acceleration;
 
  Particle(PVector _location) {
    location = _location.get(); // make a copy of given location using get()
    velocity = new PVector(random(-2.5, 2.5), random(-5, 0));
    acceleration = new PVector(0, 0.1);
  }
 
  void update() {
    velocity.add(acceleration);
    location.add(velocity);
  }
}

Comments

Nobody has said anything yet.