xxxxxxxxxx
72
let cam;
let pxSize = 10;
let lineColor1, lineColor2, lineColor3, lineColor4;
function setup() {
createCanvas(900, 600);
pixelDensity(1);
cam = createCapture(VIDEO, { flipped: true });
cam.size(90, 60);
cam.hide();
noStroke();
}
function draw() {
cam.loadPixels();
for (let x = 0; x < cam.width; x++) {
for (let y = 0; y < cam.height; y++) {
let i = 4 * (x + y * cam.width);
let r = cam.pixels[i + 0];
let g = cam.pixels[i + 1];
let b = cam.pixels[i + 2];
// let a = cam.pixels[i + 3];
let c = color(r, g, b);
let bright = brightness(c);
if (bright > 75) {
stroke("lineColor1");
strokeWeight(1);
} else if (bright > 50 && bright <= 75) {
stroke("lineColor2");
strokeWeight(1);
} else if (bright > 25 && bright <= 50) {
stroke("lineColor3");
strokeWeight(1);
} else {
stroke("lineColor4");
strokeWeight(1);
}
line(x * pxSize + pxSize, y * pxSize, x * pxSize, y * pxSize + pxSize);
line(x * pxSize, y * pxSize, x * pxSize + pxSize, y * pxSize + pxSize);
}
}
}
function keyPressed() {
console.log("Pressed key:", key); // 디버그용
if (keyCode === '1') { // 왼쪽 방향키
lineColor1 = "#00B6FF";
lineColor2 = "blue";
lineColor3 = "skyblue";
lineColor4 = "purple";
} else if (keyCode === '2') { // 위쪽 방향키
lineColor1 = "magenta";
lineColor2 = "magenta";
lineColor3 = "magenta";
lineColor4 = "magenta";
} else if (keyCode === '3') { // 오른쪽 방향키
lineColor1 = "yellow";
lineColor2 = "yellow";
lineColor3 = "yellow";
lineColor4 = "yellow";
} else if (keyCode === '4') { // 아래쪽 방향키
lineColor1 = "#EAEAEA";
lineColor2 = "#A2A2A2";
lineColor3 = "#626262";
lineColor4 = "black";
}
}