xxxxxxxxxx
66
let w = [];
let nb = 200;
function setup() {
createCanvas(windowWidth, windowHeight);
background("#4D4C7D");
initW();
noStroke();
}
function draw() {
drawW();
moveW();
snakeW();
}
function initW() {
for (let i = 0; i < nb; i++) {
w.push(createVector(width/2, height/2));
}
}
function drawW() {
for (let i = 0; i < nb; i++) {
let center = createVector(width/2,height/2)
let distance = w[i].dist(center);
let c2 = color('#E9D5CA')
let c1 = color('#827397');
let n = map(distance,0,width/6,0,1);
let c3 = lerpColor(c1,c2,n)
fill(c3);
circle(w[i].x, w[i].y, 2);
}
}
function moveW() {
for (let i = 0; i < nb; i++) {
w[i].x = w[i].x + random(-2, 2);
w[i].y = w[i].y + random(-2, 2);
}
}
function snakeW() {
for (let i = 0; i < nb; i++) {
if (w[i].x > width) { // MUR DROITE
w[i] = createVector(0, w[i].y);
}
if (w[i].x < 0) {
// MUR GAUCHE
w[i] = createVector(width, w[i].y);
}
if ( w[i].y < 0) {
// MUR HAUT
w[i] = createVector(w[i].x, height);
}
if ( w[i].y > height) {
// MUR BAS
w[i] = createVector(w[i].x, 0);
}
}
}