Skip to content

Instantly share code, notes, and snippets.

@nickgs
Last active October 25, 2020 19:43
Show Gist options
  • Save nickgs/104391ea388dde93610d27093533da64 to your computer and use it in GitHub Desktop.
Save nickgs/104391ea388dde93610d27093533da64 to your computer and use it in GitHub Desktop.
Super Basic Particle System
function setup() {
createCanvas(windowWidth, windowHeight);
background("red");
let pe = new ParticleEmitter();
pe.draw();
}
function draw() {
}
class Particle {
// we have a blueprint.
constructor(x, y) {
this.size = 10;
this.pos = createVector(x, y);
}
draw() {
ellipse(this.pos.x, this.pos.y, this.size);
}
}
class ParticleEmitter {
constructor() {
this.particles = [];
for(let i = 0; i <= 100; i++) {
this.particles[i] = new Particle(random(windowWidth), random(windowHeight));
}
}
draw() {
for(let i = 0; i <= 100; i++) {
this.particles[i].draw();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment