1 # Copyright 2018 Paul Hänsch
3 # This file is part of Serve0
5 # Serve0 is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Serve0 is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Serve0 If not, see <http://www.gnu.org/licenses/>.
19 <canvas id="lv" width="400" height="480" style="width: 50%; margin: 0;">
20 </canvas><canvas id="rv" width="400" height="480" style="width: 50%; margin: 0;"></canvas>
22 <video id="video" onclick="videoPlay();" style="position: absolute; top: 0;">
23 <source src="$(urlsafe "$video")" type='video/mp4; codecs="avc1.4D401E, mp3"'>"
26 <script type="text/javascript">
27 var render = "${render}";
28 var x, y = [], z = [], ox = 0, cnt = 0, ty, tz;
29 var video, scale, lv, rv, debug;
33 ty = 0; y.forEach( function(n, i){ ty += n;} ); ty /= 6;
34 tz = 0; z.forEach( function(n, i){ tz += n;} ); tz /= 6;
39 if ( render == "180" ) {
40 if (ox > w / 8) { ox = w / 8; } else if (ox < w / -8) { ox = w / -8; }
41 sy = ( v * h + h / 4) |0;
42 lc.drawImage(video, (w / 8 + ox) % (w/2) |0, sy, w / 4 |0, h / 2, 0, 0, lv.width, h / 2 * scale);
43 rc.drawImage(video, (w / 8 * 5 + ox) % (w/2) |0, sy, w / 4 |0, h / 2, 0, 0, rv.width, h / 2 * scale);
45 sx = (w / 8 * 3 + ox) % (w) |0;
46 lc.drawImage(video, sx, (v * h + h / 8) |0, w / 4 |0, h / 4, 0, 0, lv.width, h / 4 * scale);
47 rc.drawImage(video, sx, (v * h + h / 8 * 5) |0, w / 4 |0, h / 4, 0, 0, rv.width, h / 4 * scale);
49 lc.drawImage(video, sx + w, (v * h + h / 8) |0, w / 4 |0, h / 4, 0, 0, lv.width, h / 4 * scale);
50 rc.drawImage(video, sx + w, (v * h + h / 8 * 5) |0, w / 4 |0, h / 4, 0, 0, rv.width, h / 4 * scale);
51 } else if ( sx + w / 4 > w) {
52 lc.drawImage(video, sx - w, (v * h + h / 8) |0, w / 4 |0, h / 4, 0, 0, lv.width, h / 4 * scale);
53 rc.drawImage(video, sx - w, (v * h + h / 8 * 5) |0, w / 4 |0, h / 4, 0, 0, rv.width, h / 4 * scale);
57 lv.setAttribute("style", "transform: rotate("+r+"deg);")
58 rv.setAttribute("style", "transform: rotate("+r+"deg);")
60 requestAnimationFrame(draw);
63 w = video.videoWidth; h = video.videoHeight;
64 scale = lv.width / (w / 4);
66 video.setAttribute("style", "display: none;");
70 video = document.getElementById("video");
71 lv = document.getElementById("lv");
72 rv = document.getElementById("rv");
73 debug = document.getElementById("debug");
75 lv.setAttribute("width", "" + lv.offsetWidth);
76 rv.setAttribute("width", "" + rv.offsetWidth);
77 lv.setAttribute("height", "" + lv.offsetHeight);
78 rv.setAttribute("height", "" + rv.offsetHeight);
80 lc = lv.getContext("2d");
81 rc = rv.getContext("2d");
83 window.addEventListener("devicemotion", function(event) {
84 // x[cnt] = event.accelerationIncludingGravity.x;
85 y[cnt] = event.accelerationIncludingGravity.y;
86 z[cnt] = event.accelerationIncludingGravity.z;
93 # vi:set filetype=html: