class SmokeLayer extends Layer { ParticleSystem system; Particle last; int smokeAmount = 12; int smokeSize = 15; SmokeLayer(PApplet parent) { super(parent); } void setup() { fill(255, 64); system = new ParticleSystem(-0.1f, 0.001f); ellipseMode(LaserBurn.CENTER); smooth(); } void draw() { background(0, 0); noStroke(); int dx = (int)(random(-5, 5)); int dy = (int)(random(-5, 5)); if (mousePressed) { for (int i = 0; i < smokeAmount; i++) { Particle p = system.makeParticle(1.0f, mouseX + dx, mouseY + dy, 0); p.velocity().set(random(-1, 1), random(-2, -5), 0); if (last != null) system.makeSpring(p, last, 0.1f, 0.1f, 10); last = p; } } system.tick(); setVisible(false); for (int i = 0; i < system.numberOfParticles(); ++i) { Particle p = system.getParticle(i); if (p.age() > 40) { system.removeParticle(p); continue; } setVisible(true); fill(200, 128/( (p.age()*2)+1)); ellipse(p.position().x(), p.position().y(), smokeSize, smokeSize); } } }