Spaces:
Runtime error
Runtime error
File size: 906 Bytes
807bb16 a77de0a 807bb16 a77de0a 807bb16 1034076 807bb16 a77de0a 807bb16 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
let video;
function setup() {
createCanvas(400, 300);
video = createCapture(VIDEO);
video.hide();
video.loop();
}
function draw() {
background(0);
let xw = constrain(mouseX, 0, width);
let stepSize = floor(map(xw, 0, width, 4, 10));
video.loadPixels();
for (let y = 0; y < video.height; y += stepSize) {
for (let x = 0; x < video.width; x += stepSize) {
let i = (y * video.width + x) * 4;
let r = video.pixels[i];
let g = video.pixels[i+1];
let b = video.pixels[i+2];
let a = video.pixels[i+3];
let luma = 0.299 * r + 0.587 * g + 0.114 * b;
let diameter = map(luma, 0, 255, 0, stepSize);
fill(255);
noStroke();
ellipse(
map(video.width - x, 0, video.width, 0, width),
map(y, 0, video.height, 0, height),
diameter,
diameter
);
}
}
} |