class Parti {
//VARIABLES
float x;
float y;
float xspeed = random(1,3);
float yspeed = random(1,3);
color particlec;
float r = 8;
//CONSTRUCTOR
Parti(float _x, float _y, color _particlec){
x = _x;
y = _y;
particlec = _particlec;
}
//Random Walk
void move() {
int xstep = int(random(0,3))-1; //random walk for x
int ystep = int (random(0,3))-1; //random walk for y
x += xstep*xspeed; // acceleration
y += ystep*yspeed;
//bounce back
if ((x > width) || (x < 0)) {
xspeed = xspeed * -1;
}
if ((y > height) || (y < 0)) {
yspeed = yspeed * -1;
}
}
//draw particles
void display(){
noStroke();
fill(particlec);
ellipse (x,y, r, r);
}
//run all function
void run(){
display();
move();
}
}
//---------------------LIBRARIES
//---------------------GLOBAL VARIABLES
int particlesSize = 1000;
int particlesSize2 = 100;
color c = color(3,180,255,200); //initil particles (blue)
color c2 = color(255,150,20,200); // seondary particles (orange)
//---------------------DECLARE OBJECT
ArrayList particles;
//---------------------SETUP LOOP
void setup(){
size (1000,400);
smooth();
frameRate(30);
background (0);
//-------------------INITIALIZE OBJECT
particles = new ArrayList (); //start with empty list
for (int i = 0; i< particlesSize; i ++) {
Parti myParti = new Parti(random(0,width),random(0,height),c);
particles.add(myParti);
}
}
//---------------------DRAW LOOP
void draw(){
fill (0,10); // particles fade out
rect (0,0,width,height);
for (int i = 0; i < particles.size(); i ++) {
Parti p = (Parti) particles.get(i);
p.run();
}
if(mousePressed){// add secondary particles
for (int i = 0; i< particlesSize2; i ++) {
particles.add(new Parti(random(0,width),random(0,height),c2));
}
}
}
//---------------------ADDITIONAL FUNCTION
void keyPressed(){
saveFrame();
}