//ArrayList <Particle> ptcls;
int step = 10;
System sys;
void setup() {
size(500, 500);
sys = new System();
for (int x = 0; x < width; x+=step) {
for (int y = 0; y < height; y+=step) {
sys.ptcls.add(new Particle(x + random(-1, 1), y + random(-1, 1)));
}
}
background(240);
}
void draw() {
sys.run();
}
String timestamp() {
return year() +"-" + month() +"-" + day() +"-" + hour() +"-" + minute() +"-"+ second();
}
void keyPressed() {
if (key == 's' || key =='S') {
String filename = "out-"+ timestamp() +".png";
saveFrame(filename);
println("Saved \"" + filename+ "\" to disk");
}
}
class Trailicle extends Particle{
Trailicle(float x, float y){
super(x,y);
}
}
/*
TODO: Create different types of Particle placement
*/
class System {
ArrayList<Particle> ptcls;
System() {
this.ptcls = new ArrayList<Particle>();
}
void run() {
for (int p = 0; p < ptcls.size(); p++) {
ptcls.get(p).display();
ptcls.get(p).update();
}
}
}
class Particle {
float x = 0f;
float y = 0f;
float xoff = .0f;
float yoff = .0f;
float incr = .01f;
Particle(float x, float y) {
this.x = x;
this.y = y;
}
void display() {
strokeWeight(random(0.5, 2));
stroke(20, 10);
point(this.x, this.y);
}
void update() {
float movex = ((noise(xoff) * 2 ) - 1);
float movey = ((noise(yoff) * 2 ) - 1);
this.x += movex ;
this.y += movey;
xoff = xoff + random(-0.5, 0.5);
yoff = yoff + random(-0.5, 0.5);
}
}