xxxxxxxxxx
48
// This code is inspired by abstract portrait . I want to make it artistic and interactive by creating sequin effect, deleting the background and moving the "portait " by location of mouse.
let video;
let vScale = 16;
let degree = 0;
function setup() {
createCanvas(800, 800);
video = createCapture(VIDEO);
video.size(width / vScale, height / vScale);
video.hide();
}
function draw() {
//moving the portrait and rotate it
translate(mouseX, mouseY);
rotate(radians(degree));
degree += 1;
video.loadPixels();
for (let y = 0; y < video.height; y++) {
for (let x = 0; x < video.width; x++) {
let index = (x + y * video.width) * 4;
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);
noStroke();
fill(r, g, b);
rectMode(CENTER);
// sequins effect
ellipse(x * vScale, y * vScale, random(10, 50));
}
}
}
function mousePressed() {
let fs = fullscreen();
fullscreen(!fs);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
video.size(width / vScale, height / vScale);
}