mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 02:58:55 +01:00
awa
This commit is contained in:
parent
9e3eeb277e
commit
1370c899fa
1 changed files with 48 additions and 42 deletions
|
@ -2105,63 +2105,69 @@ if (/[?&]autoplay=/.test(location.search)) {
|
||||||
<% if(!IsOldWindows) { %>
|
<% if(!IsOldWindows) { %>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const AMvideo = document.getElementById("video");
|
const AMvideo = document.getElementById("video")
|
||||||
const oddCanvas = document.getElementById("ambient-canvas-1");
|
const oddCanvas = document.getElementById("ambient-canvas-1")
|
||||||
const evenCanvas = document.getElementById("ambient-canvas-2");
|
const evenCanvas = document.getElementById("ambient-canvas-2")
|
||||||
const oddCtx = oddCanvas.getContext("2d");
|
const oddCtx = oddCanvas.getContext("2d")
|
||||||
const evenCtx = evenCanvas.getContext("2d");
|
const evenCtx = evenCanvas.getContext("2d")
|
||||||
|
|
||||||
const canvasOpacity = "0.4";
|
const frameIntervalMs = 998
|
||||||
const baseFrameIntervalMs = 500;
|
const canvasOpacity = "0.4"
|
||||||
let intervalId;
|
|
||||||
let oddFrame = true;
|
|
||||||
|
|
||||||
const getFrameInterval = () => {
|
let intervalId
|
||||||
const coreCount = navigator.hardwareConcurrency || 2;
|
let oddFrame = true
|
||||||
return Math.max(baseFrameIntervalMs / coreCount, 33);
|
let numWorkers = navigator.hardwareConcurrency || 4
|
||||||
};
|
|
||||||
|
|
||||||
const drawFrame = () => {
|
const drawFrame = () => {
|
||||||
const ctx = oddFrame ? oddCtx : evenCtx;
|
if (oddFrame) {
|
||||||
const canvas = oddFrame ? oddCanvas : evenCanvas;
|
oddCtx.drawImage(AMvideo, 0, 0, oddCanvas.width, oddCanvas.height)
|
||||||
|
transitionToOddCanvas()
|
||||||
ctx.drawImage(AMvideo, 0, 0, canvas.width, canvas.height);
|
} else {
|
||||||
oddCanvas.style.opacity = oddFrame ? canvasOpacity : "0";
|
evenCtx.drawImage(AMvideo, 0, 0, evenCanvas.width, evenCanvas.height)
|
||||||
evenCanvas.style.opacity = oddFrame ? "0" : canvasOpacity;
|
transitionToEvenCanvas()
|
||||||
|
}
|
||||||
oddFrame = !oddFrame;
|
oddFrame = !oddFrame
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const transitionToOddCanvas = () => {
|
||||||
|
oddCanvas.style.opacity = canvasOpacity
|
||||||
|
evenCanvas.style.opacity = "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
const transitionToEvenCanvas = () => {
|
||||||
|
evenCanvas.style.opacity = canvasOpacity
|
||||||
|
oddCanvas.style.opacity = "0"
|
||||||
|
}
|
||||||
|
|
||||||
const drawStart = () => {
|
const drawStart = () => {
|
||||||
const frameIntervalMs = getFrameInterval();
|
intervalId = window.setInterval(drawFrame, frameIntervalMs / numWorkers)
|
||||||
intervalId = setInterval(drawFrame, frameIntervalMs);
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const drawPause = () => {
|
const drawPause = () => {
|
||||||
if (intervalId) clearInterval(intervalId);
|
if (intervalId) window.clearInterval(intervalId)
|
||||||
};
|
}
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
AMvideo.pause();
|
// fixes a issue where firefox/chromium fails to load the ambinet mode and doesnt load it. - please dont remove this line lmao
|
||||||
AMvideo.play();
|
video.pause();video.play();
|
||||||
AMvideo.addEventListener("play", drawStart, false);
|
|
||||||
AMvideo.addEventListener("pause", drawPause, false);
|
// DO NOT REMOVE
|
||||||
AMvideo.addEventListener("ended", drawPause, false);
|
AMvideo.addEventListener("play", drawStart, false)
|
||||||
|
AMvideo.addEventListener("pause", drawPause, false)
|
||||||
const frameIntervalMs = getFrameInterval();
|
AMvideo.addEventListener("ended", drawPause, false)
|
||||||
oddCanvas.style.transition = evenCanvas.style.transition = `opacity ${frameIntervalMs}ms`;
|
|
||||||
};
|
oddCanvas.style.transition = evenCanvas.style.transition = `opacity ${frameIntervalMs / numWorkers}ms`
|
||||||
|
}
|
||||||
|
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
AMvideo.removeEventListener("play", drawStart);
|
AMvideo.removeEventListener("play", drawStart)
|
||||||
AMvideo.removeEventListener("pause", drawPause);
|
AMvideo.removeEventListener("pause", drawPause)
|
||||||
AMvideo.removeEventListener("ended", drawPause);
|
AMvideo.removeEventListener("ended", drawPause)
|
||||||
drawPause();
|
drawPause();
|
||||||
};
|
}
|
||||||
|
|
||||||
window.addEventListener("load", init);
|
|
||||||
window.addEventListener("unload", cleanup);
|
|
||||||
|
|
||||||
|
window.addEventListener("load", init)
|
||||||
|
window.addEventListener("unload", cleanup)
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
|
|
Loading…
Reference in a new issue