pantomime/index.html
2025-06-03 21:01:00 +02:00

191 lines
4.7 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="fav_icon.ico" type="image/x-icon">
<title>Pantomime</title>
<style>
html,
body {
margin: 0;
height: 100%;
width: 100%;
}
body {
display: flex;
flex-direction: column;
height: 100dvh;
width: 100dvw;
padding: 10px;
gap: 10px;
box-sizing: border-box;
font-family: Arial, sans-serif;
align-items: center;
}
img {
width: 256px;
height: 256px;
object-fit: none;
image-rendering: pixelated;
transform: scale(300%);
}
.image-container {
width: 100%;
height: 60%;
position: relative;
display: flex;
justify-content: center;
}
.image-container img {
padding-top: 5rem;
position: absolute;
}
.hidden {
visibility: hidden;
}
.bw {
filter: grayscale(100%);
}
#timeoutInput-label,
#timeoutInput,
#button-start {
z-index: 999;
flex-shrink: 0;
box-sizing: border-box;
}
#timeoutInput-label {
font-weight: 600;
font-size: 2rem;
margin-bottom: 4px;
display: inline-block;
}
#timeoutInput {
text-align: center;
padding: 6px 10px;
font-size: 2rem;
border: 1px solid #ccc;
border-radius: 4px;
transition: border-color 0.3s ease;
cursor: pointer;
}
#timeoutInput:focus {
border-color: #007BFF;
outline: none;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
background-color: #fff;
}
#button-start {
width: 80%;
padding: 10px 20px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 2rem;
font-size: 8rem;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 5px;
}
#button-start:hover {
background-color: #0056B3;
}
#button-start:focus {
outline: none;
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.5);
}
.removed {
visibility: hidden;
height: 0;
width: 0;
}
</style>
<script>
let timeoutSeconds = 60;
let timeoutId = null;
let image_position = '';
function updateImage() {
const img = document.querySelector('img');
const gridCols = 4;
const gridRows = 6;
const cellSize = 256; // 1024 / 4
const index = Math.floor(Math.random() * (gridCols * gridRows));
const row = Math.floor(index / gridCols);
const col = index % gridCols;
const x = -col * cellSize;
const y = -row * cellSize;
const new_image_position = `${x}px ${y}px`;
if (new_image_position === image_position) {
updateImage();
return;
}
image_position = new_image_position;
img.style.objectPosition = image_position;
}
function handleClick() {
updateImage();
const start = document.getElementById("svg-start");
const next = document.getElementById("svg-next");
const btn = document.getElementById("button-start");
const img = document.getElementById("pantomime-img");
const timeoutInput = document.getElementById('timeoutInput');
const timeoutInputLabel = document.getElementById('timeoutInput-label');
timeoutSeconds = parseInt(timeoutInput.value, 10);
if (isNaN(timeoutSeconds)) timeoutSeconds = 30;
if (timeoutSeconds > 300) timeoutSeconds = 300;
timeoutInput.value = timeoutSeconds;
img.classList.remove('hidden', 'bw');
next.classList.remove('removed');
start.classList.add('removed');
timeoutInput.classList.add('hidden');
timeoutInputLabel.classList.add('hidden');
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
img.classList.add('bw');
start.classList.remove('removed');
next.classList.add('removed');
timeoutInput.classList.remove('hidden');
timeoutInputLabel.classList.remove('hidden');
}, 1000 * timeoutSeconds);
}
</script>
</head>
<body>
<label id="timeoutInput-label" for="timeoutInput">Timeout (seconds): </label>
<input type="number" step="10" id="timeoutInput" min="10" max="300" value="20">
<div class="image-container">
<img id="pantomime-img" class="hidden" src="animals.png" alt="Pantomime Image" />
</div>
<button type="button" id="button-start" onclick="handleClick()">
<svg id="svg-next" class="removed" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="18rem"
fill="#e3e3e3">
<path d="M660-240v-480h80v480h-80Zm-440 0v-480l360 240-360 240Zm80-240Zm0 90 136-90-136-90v180Z" />
</svg>
<svg id="svg-start" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="18rem" fill="#e3e3e3">
<path d="M320-200v-560l440 280-440 280Zm80-280Zm0 134 210-134-210-134v268Z" />
</svg>
</button>
</body>
</html>