xxxxxxxxxx
74
let video;
let scl= 10;
let vScale = scl;
let cols, rows;
let flowfield;
var particles = [];
let xoff = 0;
let yoff = 0;
function setup() {
createCanvas(640, 320);
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 < 100; i++) {
particles[i] = new Particle();
}
}
function draw() {
background(0);
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, 0, vScale);
let f = map(bright, 0, 255, 1, 0);
// console.log(w);
let angle = w;
let positions = createVector(x*cols, y*cols);
// var v = p5.Vector.fromAngle(angle);
positions.setMag(1);
// let flowForce = f
// this.acceleration.add(mouseForce);
// console.log(flowForce);
// flowForce.setMag(1);
flowfield[indexF] = positions;
// xoff += inc;
// stroke(50);
// push();
// translate(x * scl, y * scl);
// // rotate(v.heading());
// strokeWeight(1);
// ellipse(0, scl, f*10, f*10);
// pop();
}
}
for (var i = 0; i < particles.length; i++) {
particles[i].follow(flowfield);
particles[i].update();
particles[i].edges();
particles[i].show();
}
// fr.html(floor(frameRate()));
}