xxxxxxxxxx
60
let pos = [];
let MAXVEL = 3;
let nScale;
function setup() {
createCanvas(400, 400);
stroke(0, 130);
for (let i = 0; i < 1000; i++) {
pos.push({
x: random(width),
y: random(height),
});
}
createP("noise scale factor").style("height", "6px");
nScale = createSlider(10, 200, 100, 1);
background(255);
}
function draw() {
// background(220, 20, 120);
background(255, 10);
let mScale = nScale.value();
for (let i = 0; i < pos.length; i++) {
let xparam = pos[i].x / mScale;
let yparam = pos[i].y / mScale;
let tparam = frameCount / mScale;
let nx = noise(xparam, yparam, tparam);
let ny = noise(tparam, xparam, yparam);
// turn [0,1] -> [-3,3]
let vx = map(nx, 0, 1, -MAXVEL, MAXVEL);
let vy = map(ny, 0, 1, -MAXVEL, MAXVEL);
// update
pos[i].x += vx;
pos[i].y += vy;
// reset x
if (pos[i].x > width || pos[i].x < 0) {
pos[i].x = random(width);
}
// reset y
if (pos[i].y > height || pos[i].y < 0) {
pos[i].y = random(height);
}
// ellipse(pos.x, pos.y, 16, 24);
point(pos[i].x, pos[i].y);
}
}
function mouseClicked() {
background(255);
}