Select Text read_text.html
createvideointro.html
<!-- createvideointro.html-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Explode Image Effect 2</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #222;
background-image: url('../static/captures/back_g.png');
overflow: hidden;
}
.image-container {
position: relative;
width: 300px;
height: 570px;
background-size: cover;
background-position: center;
}
.piece {
position: absolute;
background-size: 300px 570px;
width: 30px;
height: 30px;
animation: explode 1s forwards;
pointer-events: none;
}
@keyframes explode {
to {
transform: translate(calc(var(--x) * 300px), calc(var(--y) * 300px)) rotate(calc(var(--r) * 360deg));
opacity: 0;
}
}
a {
align-items: left;
}
</style>
</head>
<body>
<div class="image-container" id="image-container"></div>
<!-- Include the explosion sound -->
<audio id="explosion-sound" src="static/assets_exp/explosion.mp3" preload="auto"></audio>
<script>
document.addEventListener("DOMContentLoaded", () => {
const container = document.getElementById("image-container");
const explosionSound = document.getElementById("explosion-sound");
const images = {{ random_images | tojson }};
const rows = 15; // Number of pieces along the vertical axis
const cols = 35; // Number of pieces along the horizontal axis
const pieceWidth = container.clientWidth / cols;
const pieceHeight = container.clientHeight / rows;
let exploded = false; // Track if the image has exploded
// Preload the audio for faster playback
explosionSound.load();
// Function to get a random image from the list
function getRandomImage() {
return images[Math.floor(Math.random() * images.length)];
}
// Function to set the container's background image
function setImage(imageUrl) {
container.style.backgroundImage = `url('${imageUrl}')`;
}
// Function to explode the image
function explodeImage() {
if (exploded) return; // Prevent multiple explosions
exploded = true;
// Play the explosion sound immediately
explosionSound.currentTime = 0; // Reset sound to start
explosionSound.play();
// Delay the creation of image pieces by 0.5 seconds (500ms)
setTimeout(() => {
// Create pieces and animate them
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const piece = document.createElement("div");
piece.classList.add("piece");
// Set size and position of each piece
piece.style.width = `${pieceWidth}px`;
piece.style.height = `${pieceHeight}px`;
piece.style.left = `${col * pieceWidth}px`;
piece.style.top = `${row * pieceHeight}px`;
// Set background position to match the piece's portion of the image
piece.style.backgroundImage = `url('${currentImage}')`;
piece.style.backgroundPosition = `-${col * pieceWidth}px -${row * pieceHeight}px`;
// Randomize animation direction and rotation
piece.style.setProperty("--x", Math.random() - 0.5); // Random horizontal direction
piece.style.setProperty("--y", Math.random() - 0.5); // Random vertical direction
piece.style.setProperty("--r", Math.random()); // Random rotation
// Append the piece to the container
container.appendChild(piece);
}
}
// Hide the whole image after creating pieces
container.style.backgroundImage = 'none';
// Clean up pieces after the animation
setTimeout(() => {
container.innerHTML = ''; // Remove all pieces
}, 1000); // Match animation duration
}, 1000); // Delay the explosion animation by 0.5 seconds (500ms)
}
// Initialize the starting image
let currentImage = getRandomImage();
setImage(currentImage);
// Listen for keydown events
document.addEventListener("keydown", (event) => {
switch (event.key.toLowerCase()) {
case 'e': // 'E' key to explode the image
explodeImage();
break;
case 'h': // 'H' key to go to /index_video
window.location.href = '/index_video'; // Redirect to the Flask route
break;
case 'r': // 'R' key to reload the page
location.reload();
break;
case 'n': // 'N' key to load a new random image
if (!exploded) {
currentImage = getRandomImage();
setImage(currentImage);
}
break;
}
});
});
</script>
</body>
</html>
Back to file list