xxxxxxxxxx
/////// By Manbir
let w, h;
let cols, rows;
let scl = 15;
let flowfield = [];
/////////////////
/////////////////
let noise;
let inc = 0.035;
let zoff = 0;
let zinc = 0.004;
/////////////////
/////////////////
let n = 50; // number of planes
let dots = [];
function setup() {
/////////////////
/////////////////
w = windowWidth * 1;
h = windowHeight * 1;
createCanvas(w, h);
// createCanvas(w, h);
// pixelDensity(1);
cols = floor(width / scl);
rows = floor(height / scl);
noise = new OpenSimplexNoise(Date.now());
/////////////////
/////////////////
// flowfield = new Array(cols * rows);
for (let i = 0; i < n; i++) {
dots.push(new Plane());
}
}
function draw() {
background(13);
stroke(222);
noFill();
noiseFeild();
for (const dot of dots) {
dot.follow(flowfield);
dot.update();
dot.show();
dot.edges();
// dot.edgesBounce();
dot.trail();
}
}
function noiseFeild() {
let xoff = 0;
for (let j = 0; j < cols ; j++) {
let yoff = 0;
for (let i = 0; i < rows ; i++) {
let x = j;
let y = i;
var index = x + y * cols;
var angle = noise.noise3D(xoff, yoff, zoff) * TWO_PI * 4;
var v = p5.Vector.fromAngle(angle);
// v.setMag(1);
flowfield[index] = v;
// push();
// stroke(222, 50);
// translate(x * scl, y * scl);
// rotate(v.heading());
// stroke(222, 50);
// strokeWeight(1);
// line(0, 0, scl, 0);
// pop();
yoff += inc;
}
xoff += inc;
}
zoff += zinc;
}