xxxxxxxxxx
final int NB_PARTICLES = 10000;
final float MAX_PARTICLE_SPEED = 4;
float noiseZ;
float noiseSpeedZ;
float stepNoiseXY;
final float TP = TWO_PI;
myVector tabParticles[];
float coeffColor;
float c1, c2;
float margin = 20;
void setup()
{
size(400, 400, P2D);
background(0);
colorMode(HSB, 255);
initialize();
}
void initialize()
{
float n;
c1 = 50 + random(0, 55);
c2 = random(255 - c1);
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(i);
}
background(0);
}
void draw()
{
fill(0, 39);
noStroke();
rect(0, 0, width, height);
noiseZ += noiseSpeedZ;
PVector mouseVector = new PVector(mouseX, mouseY);
for (int i = 0; i < NB_PARTICLES; i++)
{
tabParticles[i].update();
}
}
void mousePressed() {
initialize();
}
class myVector {
PVector pos, origin, speed = new PVector(0, 0);
color myColor;
myVector (int i) {
pos = new PVector(random(-margin, margin + width), random(-margin, margin + height));
origin = pos.get();
float n = noise(pos.x * stepNoiseXY, pos.y * stepNoiseXY, noiseZ);
myColor = color(c2 + c1 * n, 255, 255);
}
void update() {
float n = noise(origin.x * stepNoiseXY, origin.y * stepNoiseXY, noiseZ);
myColor = color(c2 + c1 * n, 255, 255);
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;
PVector tmp = origin.get();
tmp.sub(pos);
tmp.mult(.1);
speed.add(tmp);
pos.add(speed);
stroke(myColor, 160);
point(pos.x, pos.y);
}
}