forked from processing/p5.js
-
Notifications
You must be signed in to change notification settings - Fork 11
Processing transition
danagong edited this page Feb 3, 2021
·
3 revisions
class Particle { float x; float y; ArrayList history;
Particle(float x, float y) { this.x = x; this.y = y; this.history = new ArrayList(); }
void update() { this.x += random(-10, 10); this.y += random(-10, 10); for (PVector v : this.history) { v.x += random(-2, 2); v.y += random(-2, 2); }
PVector v = new PVector(this.x, this.y);
this.history.add(v);
if (this.history.size() > 100) {
this.history.remove(0);
}
}
void show() { stroke(0); fill(0, 150); ellipse(this.x, this.y, 24, 24);
noFill();
beginShape();
for (PVector pos : history) {
//fill(random(255));
//ellipse(pos.x, pos.y, i, i);
vertex(pos.x, pos.y);
}
endShape();
} }