xxxxxxxxxx
72
let particules = []
const num = 30;
let seed;
function setup() {
createCanvas(1080/2, 1080/2);
for(let i=0; i<num; i++) {
particules[i] = [random(width/2 + 300, width + 300) , random(height)];
}
fill(255, 255, 255, 255);
noStroke();
}
const noiseScale = 0.005;
function draw() {
background(0, 0, 0, 7);
console.log(frameCount);
for(let i=0; i<num; i++) {
// On utilise le Perlin noise :
// Je prends les positions de départ de chacune des particules:
let n = noise(particules[i][0] * noiseScale, particules[i][1] * noiseScale);
let a = Math.PI * 2 * n; // Ici on mappe le n qui est entre 0 et 1 à entre 0 et Math.PI * 2, qui sont les angles 0 à 360 deg.
ellipse(particules[i][0], particules[i][1], 30);
particules[i][0] += cos(a); // on converti l'angle en x
particules[i][1] += sin(a); // on converti l'angle en y
if(!onScreen(particules[i])) {
particules[i][0] = width;
particules[i][1] = random(height);
}
}
}
function onScreen(position) {
return position[0] >= -500 && position[0] <= width + 500 && position[1] >= -500 && position[1] <= height + 500
}