xxxxxxxxxx
ArrayList<ParticleSystem> systems;
void setup(){
fullScreen(P2D);
systems = new ArrayList<ParticleSystem> ();
}
float q = 0 ;
float e = 0;
float t = 0;
float o = 0;
PVector ori = new PVector(q + e, t + o);
void keyPressed(){
if(key == CODED ){
if(keyCode == RIGHT){
q += 0.9;
}else if(keyCode == LEFT){
e -= 0.9;
}else if(keyCode == UP){
t -=0.9;
}else if(keyCode == DOWN){
o += 0.9;
}
}
}
void draw(){
background(250);
if (mousePressed == true){
systems.add(new ParticleSystem(new PVector(mouseX ,mouseY)));
}
for(ParticleSystem ps : systems){
ps.run();
ps.addParticle();
}
}
import java.util.*;
class ParticleSystem{
ArrayList particles;
PVector origin;
ParticleSystem(PVector location){
origin = location.get();
particles = new ArrayList();
}
void addParticle(){
particles.add(new Particle(origin));
}
void run(){
Iterator<Particle> it =
particles.iterator();
while (it.hasNext()){
Particle p = it.next();
p.run();
if(p.isDead()){
it.remove();
}
}
}
}
class Particle{
PVector location;
PVector velocity;
PVector acceleration;
float lifespan;
Particle(PVector l){
location = l.get();
acceleration = new PVector(0,0.05);
velocity = new PVector(random(-1,1),random(0,2));
lifespan = 180;
}
void run(){
update();
display();
}
void update(){
velocity.add(acceleration);
location.add(velocity);
location.x += q + e;
location.y += t + o;
lifespan -= 6;
}
void display(){
noStroke();
fill(5,lifespan);
ellipse(location.x,location.y,5,5);
}
boolean isDead(){
if(lifespan < 0){
return true;
}else{
return false;
}
}
}