-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframe.js
More file actions
39 lines (30 loc) · 936 Bytes
/
Copy pathframe.js
File metadata and controls
39 lines (30 loc) · 936 Bytes
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
const density = "43210?!abc;:+=-,._ ";
function setup() {
noCanvas();
capture = createCapture(VIDEO);
capture.size(208*1.1, 117*1.1);
//capture.size(windowWidth,windowHeight);
capture.hide();
asciiDiv = createDiv();
}
function draw() {
capture.loadPixels();
let asciiFrame = "";
for (let j = 0; j < capture.height; j++) {
for (let i = 0; i < capture.width; i++) {
const pixelIndex = (i + j * capture.width) * 4;
const r = capture.pixels[pixelIndex + 0];
const g = capture.pixels[pixelIndex + 1];
const b = capture.pixels[pixelIndex + 2];
const avg = (r + g + b) / 3;
const len = density.length;
const charIndex = floor(map(avg, 0, 255, len, 0));
const c = density.charAt(charIndex);
if (c == " ") asciiFrame += " ";
else asciiFrame += c;
}
asciiFrame += "<br/>";
}
asciiDiv.html(asciiFrame);
asciiDiv.addClass('camera');
}