-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
109 lines (86 loc) · 3.25 KB
/
index.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ASCII</title>
<style>
* {
padding: 0;
margin: 0;
}
</style>
</head>
<body style="display: flex; flex-direction: row; justify-content: center; background-color: #222;">
<video id="video" autoplay="true" hidden></video>
<canvas id="camera" hidden></canvas>
<canvas id="rosto" style="transform:rotateY(180deg)"></canvas>
</body>
<script>
const video = document.querySelector("#video");
const camera = document.querySelector('#camera');
const rosto = document.querySelector('#rosto');
window.addEventListener('resize', function (event) {
camera.width = window.innerWidth
camera.height = window.innerHeight
rosto.width = window.innerWidth
rosto.height = window.innerHeight
}, true);
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (err0r) {
console.log("Something went wrong!");
});
}
const asciiA = `$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^\`'. `
const asciiB = `" .:-=+*#%@"`
const alfabeto = asciiB.split("")
const unidade = 15;
/*
window.innerWidth > window.innerHeight ?
(5 / 100) * window.innerHeight :
(5 / 100) * window.innerWidth;
*/
setInterval(() => {
const context = rosto.getContext('2d');
context.clearRect(0, 0, rosto.width, rosto.height);
const ctx = camera.getContext('2d').drawImage(video, 0, 0, camera.width, camera.height);
for (let x = 0; x < camera.width; x = x + unidade) {
for (let y = 0; y < camera.height; y = y + unidade) {
const cameraCtx = camera.getContext('2d');
const p = cameraCtx.getImageData(x, y, unidade, unidade).data;
const luminosidade = (0.299 * p[0] + 0.587 * p[1] + 0.114 * p[2]);
const hex = "#" + ("000000" + rgbToHex(p[0], p[1], p[2])).slice(-6);
const rostoCtx = rosto.getContext('2d');
const index = Math.ceil(luminosidade / 25)
let letra = alfabeto[index]
// rostoCtx.fillStyle = "#fff" + index;
rostoCtx.fillStyle = hex;
//desenhar
rostoCtx.font = `${unidade}px Arial`;
rostoCtx.fillText(letra, x, y);
}
}
}, 1);
function mensagem() {
if (y == 350) {
const mensagem = "Mensagem escondida dentro do vídeo hahahahahahahahah"
const mostra = Math.random() > 0.5;
if (mostra) {
const lista = mensagem.split("");
const novaLetra = lista[x / unidade]
letra = novaLetra || x;
};
}
}
function rgbToHex(r, g, b) {
if (r > 255 || g > 255 || b > 255)
throw "Invalid color component";
return ((r << 16) | (g << 8) | b).toString(16);
}
</script>
</html>