xxxxxxxxxx
66
var video;
var vScale = 16;
var slider;
var particles = [];
function setup() {
createCanvas(640, 480);
pixelDensity(1);
video = createCapture(VIDEO);
video.size(width / vScale, height / vScale);
for (var i = 0; i < 100; i++) {
particles[i] = new Particle(random(width), random(height));
}
slider = createSlider(0, 255, 127);
background(0);
}
function draw() {
video.loadPixels();
for (var i = 0; i < particles.length; i++) {
particles[i].update();
particles[i].show();
}
}
function Particle(x, y) {
this.x = x;
this.y = y;
this.r = 0.001
this.update = function() {
this.x += random(-10, 10);
this.y += random(-10, 10);
this.x = constrain(this.x, 0, width);
this.y = constrain(this.y, 0, height);
this.r = this.r+1
}
this.show = function() {
noStroke();
var px = floor(this.x / vScale);
var py = floor(this.y / vScale);
var Color = video.get(px, py);
console.log(Color)
fill(Color[0], 0, Color[2], slider.value());
ellipse(this.x, this.y, this.r, this.r);
}
}