xxxxxxxxxx
final int NB_PARTICLES = 6000;
final float MAX_PARTICLE_SPEED = 3;
float noiseZ;
float noiseSpeedZ, stepNoiseXY;
final float TP = TWO_PI;
myVector tabParticles[];//array of particles
float c1, c2;
void setup()
{
size(400, 400, P2D);
background(0);
colorMode(HSB, 255);
initialize();
}
void initialize()
{
c1 = random(85, 110);
c2 = random(255 - c1);
noiseZ = random(123456);
noiseSpeedZ = random(.005, .015) * (random(1) < .5 ? 1 : -1);
stepNoiseXY = random(.001, .01);
tabParticles = new myVector[NB_PARTICLES];
for (int i = 0; i < NB_PARTICLES; i++) {
tabParticles[i] = new myVector();
}
background(0);
}
void draw()
{
fill(0, 89);
noStroke();
rect(0, 0, width, height);
noiseZ += noiseSpeedZ;
for (int i = 0; i < NB_PARTICLES; i++){
tabParticles[i].update();
}
}
void mousePressed() {
initialize();
}
void keyPressed() {
for (int i = 0; i < NB_PARTICLES; i++) {
tabParticles[i] = new myVector();
}
}
class myVector {
float x, y;
color myColor;
myVector () {
initPart();
}
void initPart(){
x = random(width);
y = random(height);
float n = noise(x * stepNoiseXY, y * stepNoiseXY, noiseZ);
myColor = color(c2 + c1 * n, 255, 255);
}
void update(){
float n = (noise(x*stepNoiseXY, y*stepNoiseXY, noiseZ));
n = map(n, .1, .9, 0, TP);
x += n*cos(n * TP) * MAX_PARTICLE_SPEED;
y += n*sin((1-n) * TP) * MAX_PARTICLE_SPEED;
if ((x < 0) || (x > width) ||
(y < 0) || (y > height)) {
initPart();
}
stroke(myColor, 80);
point(x, y);
}
}