/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.esgukpYjlrR/rev.5 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * Colorful Circle Particles (v1.1) * GoToLoop (2016-Jul-11) * * forum.Processing.org/two/discussion/17453/class-parameters * studio.ProcessingTogether.com/sp/pad/export/ro.9tixqv9DytSpX */ import java.util.List; static final boolean ONLINE = 1/2 == 1/2.; static final PVector ACC = new PVector(0, .05); final ParticleSystem ps = new ParticleSystem(); void setup() { size(800, 480, ONLINE? P2D : FX2D); smooth(3); frameRate(60); noStroke(); ellipseMode(CENTER); mouseX = mouseY = width>>1; } void draw() { background(0); ps.action().addParticle(); } class ParticleSystem { final List<Particle> particles = new ArrayList<Particle>(); ParticleSystem addParticle() { particles.add(new Particle()); return this; } ParticleSystem action() { for (int len = particles.size(), i = len; i-- != 0; ) if (particles.get(i).action()) { particles.set(i, particles.get(--len)); particles.remove(len); } return this; } } class Particle { static final int HEALTH = 0400, LIFELOSS = 2, DIAM = 5; int lifespan = HEALTH; final color c = (color) random(#000000); final PVector loc = new PVector(mouseX, mouseY); final PVector vel = new PVector(random(-1, 1), random(-2)); boolean action() { return update().display().isDead(); } Particle update() { vel.add(ACC); loc.add(vel); lifespan -= LIFELOSS; return this; } Particle display() { fill(c, lifespan); ellipse(loc.x, loc.y, DIAM, DIAM); return this; } boolean isDead() { return lifespan <= 0; } }