final int NB_PARTICLES = 6000;
final float MAX_PARTICLE_SPEED = 2.5;
PVector s = new PVector(random(0), random(0));
PVector[] p = new PVector[4];
float rotSpeed = random(.002, .03);
noiseXY = noiseXY = random(123456);
noiseSpeed = random(.01, .02) * (random(1)<.5?1:-1);
coeffColor = random(.7, 2.3);
stepNoiseXY = random(.004, .01);
tabParticles = new myVector[NB_PARTICLES];
for (int i = 0; i < NB_PARTICLES; i++) {
tabParticles[i] = new myVector();
R = min(height, width)/2;
myPg = createGraphics(width, height, P2D);
theta = TWO_PI / nbSymetries;
for (int i = 0; i < 4; i++){
p[i] = new PVector(width/2, height/2);
c = new PVector(width/2, height/2);
myPg.rect(0, 0, width, height);
for (int i = 0; i < NB_PARTICLES; i++){
tabParticles[i].update();
float angle1 = theta - rot;
float angle2 = theta + rot;
p[0] = new PVector(c.x - d/2 * cos(angle2), c.y - d/2 * sin(angle2));
p[1] = new PVector(c.x + d/2 * cos(angle1), c.y - d/2 * sin(angle1));
p[2] = new PVector(c.x + d/2 * cos(angle2), c.y + d/2 * sin(angle2));
p[3] = new PVector(c.x - d/2 * cos(angle1), c.y + d/2 * sin(angle1));
for (int i = 0; i < 4 && found == false; i++){
if (p[i].x > width || p[i].x < 0){
}else if (p[i].y > height || p[i].y < 0){
if (found) rotSpeed = -rotSpeed;
translate(width/2, height/2);
for (int i = 0; i < nbSymetries; i++){
vertex(0, 0, (p[0].x+p[3].x)/2, (p[0].y+p[3].y)/2);
vertex(R*cos(i*TWO_PI/nbSymetries), R*sin(i*TWO_PI/nbSymetries), (i%2 == 0) ? p[1].x : p[2].x, (i%2 == 0) ? p[1].y : p[2].y);
vertex(R*cos((i+1)*TWO_PI/nbSymetries), R*sin((i+1)*TWO_PI/nbSymetries), (i%2 == 0) ? p[2].x : p[1].x, (i%2 == 0) ? p[2].y : p[1].y);
if (mouseButton == LEFT){
}else if (mouseButton == RIGHT){
rotSpeed = rotSpeed == 0 ? random(.002, .03)*(random(1)<.5?1:-1) : 0;
float x, y, prevX, prevY, vx, vy;
x = prevX = random(width);
y = prevY = random(height);
float n = noise(noiseXY+x*stepNoiseXY, noiseXY+y*stepNoiseXY);
vx = (1-n)*2*cos(n * TWO_PI)*MAX_PARTICLE_SPEED;
vy = (1-n)*2*sin(n * TWO_PI)*MAX_PARTICLE_SPEED;
vx = constrain(vx, -MAX_PARTICLE_SPEED, MAX_PARTICLE_SPEED);
vy = constrain(vy, -MAX_PARTICLE_SPEED, MAX_PARTICLE_SPEED);
if (x < 0 || x > width || y < 0 || y > height) {
x = prevX = random(width);
y = prevY = random(height);
n = noise(noiseXY+x*stepNoiseXY, noiseXY+y*stepNoiseXY);
myColor = color((255-n*255)*coeffColor, 255-n*126*coeffColor, 255*n*coeffColor);
myPg.stroke(myColor, 120);
myPg.line(prevX, prevY, x, y);