xxxxxxxxxx
48
let video;
let vScale = 16;
function setup() {
createCanvas(windowWidth, windowHeight);
//pixelDensity(1);
video = createCapture(VIDEO);
video.size(width / vScale, height / vScale);
video.hide();
//video.hide();
}
function draw() {
background(200,100,60,100);
video.loadPixels();
translate(width / 2, height / 2);
rotate(PI / 3.0);
for (let y = 0; y < video.windowHeight; y = y + 1) {
for (let x = 0; x < video.windowWidth; x = x + 1) {
// let index = (x + (y * video.width)) * 4;
let index = 4 * x + 4 * (y * video.windowWidth);
let r = video.pixels[index + 0];
let g = video.pixels[index + 1];
let b = video.pixels[index + 2];
let bright = (r + g + b) / 3;
// size of the rectangle is set according to brightness level!
let rectSize = map(bright, 0, 255, 0, vScale);
noStroke();
fill(r,g,b);
rectMode(CENTER);
//rect(x * vScale, y * vScale, rectSize, rectSize);
// triangle(x * vScale, y * vScale, r,g,b,vScale);
//ellipse(x * vScale, y * vScale, random(5,50))
push();
translate(x * vScale - windowWidth / 2, y * vScale - windowHeight / 2, 0);
noStroke();
ellipse(x * vScale, y * vScale, random(5,50));
pop();
}
}
}
function mousePressed() {
let fs = fullscreen();
fullscreen(!fs);}