-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojector.html
More file actions
83 lines (74 loc) · 2.05 KB
/
projector.html
File metadata and controls
83 lines (74 loc) · 2.05 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Projector</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
overflow: hidden;
}
canvas {
display: block;
width: 100%;
height: 100%;
background-color: black;
}
</style>
</head>
<body>
<canvas id="projectionCanvas"></canvas>
<script src="lines_api.js"></script>
<script src="zigzag_api.js"></script>
<script src="text_api.js"></script>
<script src="shapes_api.js"></script>
<script src="images_api.js"></script>
<script>
const canvas = document.getElementById('projectionCanvas');
let prevEvtData = null;
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
if (prevEvtData != null) {
drawEvtData(prevEvtData);
}
}
let debounceTimer;
window.addEventListener('resize', () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(resizeCanvas, 100);
});
window.addEventListener("message", (event) => {
prevEvtData = event.data;
drawEvtData(event.data);
});
function drawEvtData(evt_data) {
if (!evt_data || !evt_data.scene) {
console.error("Invalid event data or missing scene type:", evt_data);
return; // Log the error and terminate the function if validation fails
}
if (evt_data.scene === "lines") {
drawLines(evt_data);
} else if (evt_data.scene === "zigzag") {
drawZigzags(evt_data);
} else if (evt_data.scene === "text") {
drawText(evt_data);
} else if (evt_data.scene === "shapes") {
drawShapes(evt_data);
} else if (evt_data.scene === "images") {
drawImages(evt_data);
} else {
console.error("Unsupported scene type:", evt_data.scene);
}
}
window.onload = resizeCanvas
</script>
</body>
</html>