xxxxxxxxxx
72
let video;
let scl= 8;
let vScale = scl;
let cols, rows;
let flowfield;
var particles = [];
let xoff = 0;
let yoff = 0;
function setup() {
createCanvas(600, 400);
pixelDensity(1);
cols = floor(width / scl);
rows = floor(height / scl);
video = createCapture(VIDEO);
video.size(width/vScale, height/vScale);
flowfield = new Array(rows * cols);
for (var i = 0; i < 1000; i++) {
particles[i] = new Particle();
}
}
function draw() {
background(0, 80);
video.loadPixels();
loadPixels();
for (let y = 0; y < video.height; y++) {
for (let x = 0; x < video.width; x++) {
let index = (video.width - x + 1 + (y * video.width))*4;
var indexF = x + y * cols;
let r = video.pixels[index+0];
let g = video.pixels[index+1];
let b = video.pixels[index+2];
let bright = (r+g+b)/3;
let w = map(bright, 0, 255, vScale, 0);
let angle = w
var v = p5.Vector.fromAngle(angle);
// let flowForce = createVector(w, w);
// this.acceleration.add(mouseForce);
v.setMag(1);
flowfield[indexF] = v;
// xoff += inc;
stroke(250);
push();
translate(x * scl, y * scl);
rotate(v.heading());
strokeWeight(1);
line(0, 0, scl, 0);
pop();
}
}
for (var i = 0; i < particles.length; i++) {
particles[i].follow(flowfield);
particles[i].update();
particles[i].edges();
particles[i].show();
}
}