class PSystem
{
float th;
PVector ps_loc;
ArrayList particles;
public PSystem(PVector ps_loc, int num, float th)
{
this.ps_loc = ps_loc;
this.th = th;
particles = new ArrayList();
for (int i = 0; i < num; i++) {
particles.add(new Particle(new PVector(), new PVector(), new PVector(ps_loc.x, ps_loc.y, 0), random(1.0, 70.0), i));
}
}
void run()
{
update();
for (int i = particles.size()-1; i >= 0; i--) {
Particle prt = (Particle) particles.get(i);
prt.run();
prt.move(new PVector(ps_loc.x,ps_loc.y,0));
}
//ellipse(ps_loc.x,ps_loc.y, 10, 10);
}
void update()
{
th += 0.0025f;
ps_loc.x = inx + r * cos(th);
ps_loc.y = iny + r * sin(th);
ps_loc.x += random(-30.0f, 30.0f);
ps_loc.y += random(-30.0f, 30.0f);
}
}
int numSystems = 110;
PSystem[] ps = new PSystem[numSystems];
float theta, theta2 = 0.0f;
float r;
float amplitude;
float x, y;
float inx, iny;
PVector centerLoc;
PFont font;
void setup()
{
size(640, 480, P2D);
colorMode(HSB, 360, 100, 100, 100);
font = loadFont("Standard0757-8.vlw");
textFont(font);
inx = width/2;
iny = height/2;
centerLoc = new PVector(width/2, height/2, 0);
for(int i=0; i<numSystems; i++){
// dispose PSystems in a circle
x = r * cos(theta);
y = r * sin(theta);
x += inx;
y += iny;
ps[i] = new PSystem(new PVector(x, y, 0), 100, theta);
theta += 0.0572;
}
r = 40.0f;
amplitude = r;
}
void draw()
{
noSmooth();
background(224, 94, 28, 100);
waveR();
// cycle and run all the PSystems
for(int i = 0; i < numSystems; i++)
{
ps[i].run();
}
fill(0, 0, 0);
noStroke();
smooth();
//ellipse(width/2, height/2, 130, 130);
// the framerate
fill(1, 0, 100, 50);
text(round(frameRate), 620, 460);
}
void waveR()
{
theta += 0.05;
r = theta;
r = sin(r)*amplitude;
r += 100;
}
class Particle {
PVector loc;
PVector vel;
PVector acc;
float ms;
float counter;
Particle(PVector a, PVector v, PVector l, float ms_, float counter_) {
acc = a;
vel = v;
loc = l;
ms = ms_;
counter = counter_;
}
void run() {
update();
render();
}
void update() {
vel.add(acc);
loc.add(vel);
acc = new PVector();
}
void render() {
noStroke();
fill(257, 28, 65, 10);
ellipse(loc.x,loc.y, ms/8, ms/8);
stroke(238, 14, 85, 30);
point(loc.x,loc.y);
float al = map(vel.mag(), 0, 1.2, .1, 3);
stroke(238, 14, 85, al);
//print(counter%5 + " ");
if(ms >= 69.5) line(inx,iny,loc.x,loc.y);
}
void move(PVector target) {
acc.add(steer(target));
}
PVector getLocation() {
return loc;
}
PVector steer(PVector target) {
PVector steer;
PVector desired = PVector.sub(target,loc);
float d = desired.mag();
desired.normalize();
desired.mult(3.5f);
steer = PVector.sub(desired,vel);
steer.limit(3.0f);
steer.div(ms);
return steer;
}
}