xxxxxxxxxx
54
const flowfield = [];
const points = [];
let grid, cols, rows, n
function setup() {
createCanvas(w = 600, h = 600);
grid = w / 100
n = w * 4
rows = floor(h / grid)
cols = floor(w / grid)
for (let j = 0; j < rows; j++) {
for (let i = 0; i < cols; i++) {
let angle = noise(i * 0.1, j * 0.1) * TAU
let v = createVector(cos(angle), sin(angle))
flowfield.push(v)
}
}
for (let i = 0; i < n; i++){
points[i] = createVector(random(w), random(h))
}
// noLoop();
background(10);
}
function draw() {
// for (let j = 0; j < rows; j++) {
// for (let i = 0; i < cols; i++) {
// let index = i + j * cols
// push();
// translate(i * grid + grid / 2, j * grid + grid / 2)
// rotate(flowfield[index].heading());
// strokeWeight(1);
// line(0, 0, grid, 0);
// pop();
// }
// }
for (let p of points) {
let x = floor(p.x / grid), y = floor(p.y / grid);
let index = x + y * cols;
let force = flowfield[index];
p.add(force);
stroke(255, 50)
point(p.x, p.y)
}
}