xxxxxxxxxx
final int NB_PARTICLES = 350;
final int W = 200;
final float MAX_PARTICLE_SPEED = 4;
int count = 0;
final int nbZ = 200;
int mode = 0;
float noiseZ;
float noiseSpeedZ;
float stepNoiseXY;
final float TP = TWO_PI;
myVector tabParticles[];
float coeffColor;
float margin = 20;
void setup() {
size(400, 400, P3D);
background(0);
colorMode(HSB, 255);
noFill();
strokeWeight(3);
initialize();
}
void initialize()
{
float n;
count = 0;
noiseZ = random(123456);
noiseSpeedZ = random(.01, .02) * (random(1) < .5 ? 1 : -1);
coeffColor = random(.3);
stepNoiseXY = random(.007, .013);
tabParticles = new myVector[NB_PARTICLES];
for (int i = 0; i < NB_PARTICLES; i++) {
tabParticles[i] = new myVector();
}
background(0);
}
void draw() {
background(0);
noiseZ += noiseSpeedZ;
PVector mouseVector = new PVector(mouseX, mouseY);
translate(width/2, height/2);
rotateY(PI+map(mouseX, 0, width, -TP, TP));
rotateX(map(mouseY, 0, height, -TP, TP));
translate(0, 0, -Math.min(count, nbZ)/2);
for (int i = 0; i < NB_PARTICLES; i++) {
tabParticles[i].update();
}
count++;
}
void mousePressed() {
initialize();
}
class myVector {
PVector pos, origin, speed = new PVector(0, 0, 0);
PVector[] poss;
myVector () {
poss = new PVector[nbZ];
pos = new PVector(random(-W/2, W/2), random(-W/2, W/2), 0);
origin = pos.get();
}
void update() {
float n;
if (mode == 0) {
n = noise(origin.x * stepNoiseXY, origin.y * stepNoiseXY, noiseZ);
n = .8 * (n - .5);
speed.x = n*2*cos(n * TP) * MAX_PARTICLE_SPEED;
speed.y = n*2*sin((1-n) * TP) * MAX_PARTICLE_SPEED;
} else {
n = noise(pos.x*stepNoiseXY, pos.y*stepNoiseXY, noiseZ);
n = map(n, .1, .9, 0, TP);
speed.x = .3*n*cos(n * TP) * MAX_PARTICLE_SPEED;
speed.y = .3*n*sin((1-n) * TP) * MAX_PARTICLE_SPEED;
}
PVector tmp = origin.get();
tmp.sub(pos);
tmp.mult(.1);
speed.add(tmp);
pos.add(speed);
poss[count%nbZ] = pos.get();
// println("- - - - - - - count%nbZ: " + count%nbZ);
beginShape();
int l = Math.min(nbZ, count), k;
for (int i = 1; i < l; i ++) {
k = count >= nbZ ? (count + i) % nbZ : i;
stroke(i, 180);
// println("k: " + k);
// stroke(poss[k].z, 255, 255);
vertex(poss[k].x, poss[k].y, i);
}
endShape();
// println("- - - - - - - poss[0].x: " + poss[0].x);
}
}
void keyPressed() {
mode = (mode+1)%2;
}