elevator-sim / index.html
szsheep's picture
Add 2 files
cfc8f8d verified
Raw History Blame Contribute Delete
24.2 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elevator Simulator</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Digital+7&display=swap');
.elevator-door {
transition: all 1s ease-in-out;
position: relative;
z-index: 10;
}
.doors-open .door-left {
transform: translateX(-100%);
}
.doors-open .door-right {
transform: translateX(100%);
}
.elevator-button {
transition: all 0.2s ease;
aspect-ratio: 1/1;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-width: 60px;
font-size: 1.5rem;
}
.control-button {
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
font-size: 0.9rem;
padding: 0.5rem;
height: auto;
}
.elevator-button.active {
background-color: #ffcc00;
box-shadow: 0 0 15px #ffcc00;
}
.seven-segment {
font-family: 'Digital 7', sans-serif;
color: #ff0000;
text-shadow: 0 0 5px #ff0000;
font-size: 4rem;
}
.floor-indicator {
transition: all 0.5s ease;
}
@keyframes moveUp {
0% { transform: translateY(0); }
100% { transform: translateY(-100%); }
}
@keyframes moveDown {
0% { transform: translateY(0); }
100% { transform: translateY(100%); }
}
.moving-up {
animation: moveUp 1s linear infinite;
}
.moving-down {
animation: moveDown 1s linear infinite;
}
.control-panel {
scrollbar-width: none;
-ms-overflow-style: none;
}
.control-panel::-webkit-scrollbar {
display: none;
}
.floor-display-container {
height: 100px;
background-color: #111;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
padding: 0 20px;
}
.direction-arrow {
font-size: 3rem;
margin-left: 20px;
opacity: 0;
transition: opacity 0.3s ease;
}
.direction-arrow.active {
opacity: 1;
}
.up-arrow {
color: #ff0000;
}
.down-arrow {
color: #0066ff;
}
.button-gap {
margin-bottom: 1rem;
}
</style>
</head>
<body class="bg-gray-900 min-h-screen flex items-center justify-center p-4">
<div class="relative bg-gray-800 rounded-xl p-6 shadow-2xl w-full max-w-4xl">
<h1 class="text-4xl font-bold text-center text-white mb-6">Elevator Simulator</h1>
<div class="flex flex-col md:flex-row gap-6">
<!-- Elevator shaft with doors -->
<div class="w-full md:w-2/3 relative h-[600px] bg-gray-700 rounded-xl overflow-hidden">
<!-- Floor indicator strip -->
<div class="absolute left-0 right-0 top-0 h-24 bg-gray-900 flex justify-center items-center px-6">
<div class="floor-display-container">
<div class="seven-segment font-bold" id="floor-display">1</div>
<div class="direction-arrow up-arrow" id="up-arrow">↑</div>
<div class="direction-arrow down-arrow" id="down-arrow">↓</div>
</div>
</div>
<!-- Elevator doors -->
<div class="absolute bottom-0 left-0 right-0 h-[480px] bg-gray-600 flex">
<div class="elevator-door door-left w-1/2 h-full bg-gray-500 border-r-2 border-gray-700"></div>
<div class="elevator-door door-right w-1/2 h-full bg-gray-500 border-l-2 border-gray-700"></div>
</div>
<!-- Elevator interior -->
<div class="absolute bottom-0 left-0 right-0 h-[480px] bg-gray-400 flex items-center justify-center">
<div class="text-gray-700 font-bold text-2xl">Welcome!</div>
</div>
<!-- Moving pattern for animation -->
<div class="absolute top-24 left-0 right-0 h-[480px] overflow-hidden">
<div class="h-full w-full relative" id="moving-pattern">
<div class="absolute top-0 left-0 right-0 h-full bg-gray-600"></div>
<div class="absolute top-full left-0 right-0 h-full bg-gray-600"></div>
<div class="absolute top-0 left-0 right-0 h-full bg-gray-600 floor-indicator" id="floor-indicator"></div>
</div>
</div>
</div>
<!-- Elevator control panel -->
<div class="w-full md:w-1/3">
<div class="bg-gray-700 rounded-xl p-6 h-[600px] overflow-y-auto control-panel">
<div class="grid grid-cols-4 gap-4">
<!-- Floor buttons -->
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="16">16</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="15">15</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="14">14</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="13">13</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="12">12</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="11">11</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="10">10</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="9">9</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="8">8</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="7">7</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="6">6</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="5">5</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="4">4</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="3">3</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="2">2</button>
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="1">1</button>
<!-- Bigger gap before control buttons -->
<div class="col-span-4 button-gap"></div>
<!-- Control buttons -->
<button class="control-button bg-red-500 rounded-lg text-white font-bold col-span-2" id="emergency">EMERGENCY</button>
<button class="control-button bg-yellow-500 rounded-lg text-black font-bold col-span-2" id="door-open">DOOR OPEN</button>
<button class="control-button bg-yellow-500 rounded-lg text-black font-bold col-span-2" id="door-close">DOOR CLOSE</button>
<button class="control-button bg-green-500 rounded-lg text-black font-bold col-span-2" id="alarm">ALARM</button>
</div>
</div>
</div>
</div>
<div class="mt-6 text-white">
<h2 class="font-bold text-2xl mb-3">Elevator Status:</h2>
<div id="status-message" class="bg-gray-700 p-4 rounded-lg text-xl">Ready</div>
</div>
</div>
<audio id="door-open-sound" src="https://www.soundjay.com/mechanical/sounds/elevator-door-open-01.mp3" preload="auto"></audio>
<audio id="door-close-sound" src="https://www.soundjay.com/mechanical/sounds/elevator-door-close-01.mp3" preload="auto"></audio>
<audio id="floor-reached-sound" src="https://www.soundjay.com/mechanical/sounds/elevator-ding-01.mp3" preload="auto"></audio>
<audio id="moving-sound" src="https://www.soundjay.com/mechanical/sounds/elevator-move-01.mp3" preload="auto"></audio>
<audio id="alarm-sound" src="https://www.soundjay.com/mechanical/sounds/siren-01.mp3" preload="auto"></audio>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Elevator state
const elevator = {
currentFloor: 1,
targetFloors: [],
direction: 'idle', // 'up', 'down', 'idle'
isMoving: false,
doorsOpen: false,
movingSound: document.getElementById('moving-sound'),
doorOpenSound: document.getElementById('door-open-sound'),
doorCloseSound: document.getElementById('door-close-sound'),
floorReachedSound: document.getElementById('floor-reached-sound'),
alarmSound: document.getElementById('alarm-sound'),
floorChangeInterval: null,
alarmActive: false
};
// DOM elements
const floorDisplay = document.getElementById('floor-display');
const upArrow = document.getElementById('up-arrow');
const downArrow = document.getElementById('down-arrow');
const statusMessage = document.getElementById('status-message');
const floorIndicator = document.getElementById('floor-indicator');
const movingPattern = document.getElementById('moving-pattern');
const doorLeft = document.querySelector('.door-left');
const doorRight = document.querySelector('.door-right');
const doorsContainer = document.querySelector('.bg-gray-600.flex');
const elevatorButtons = document.querySelectorAll('.elevator-button[data-floor]');
const emergencyButton = document.getElementById('emergency');
const doorOpenButton = document.getElementById('door-open');
const doorCloseButton = document.getElementById('door-close');
const alarmButton = document.getElementById('alarm');
// Initialize
updateDisplay();
// Event listeners for floor buttons
elevatorButtons.forEach(button => {
button.addEventListener('click', function() {
if (elevator.alarmActive) return;
const floor = parseInt(this.dataset.floor);
if (!elevator.targetFloors.includes(floor) && floor !== elevator.currentFloor) {
elevator.targetFloors.push(floor);
this.classList.add('active');
updateStatus(`Floor ${floor} added to queue`);
// If elevator is idle, start moving
if (elevator.direction === 'idle') {
determineDirection();
moveToNextFloor();
}
}
});
});
// Emergency button
emergencyButton.addEventListener('click', function() {
if (elevator.isMoving) {
emergencyStop();
} else {
resetElevator();
}
});
// Alarm button
alarmButton.addEventListener('click', function() {
if (elevator.alarmActive) {
// Stop alarm
elevator.alarmSound.pause();
elevator.alarmActive = false;
this.classList.remove('bg-red-500');
this.classList.add('bg-green-500');
updateStatus('Alarm deactivated');
} else {
// Start alarm
elevator.alarmSound.currentTime = 0;
elevator.alarmSound.loop = true;
elevator.alarmSound.play();
elevator.alarmActive = true;
this.classList.remove('bg-green-500');
this.classList.add('bg-red-500');
updateStatus('ALARM ACTIVATED!');
}
});
// Door controls
doorOpenButton.addEventListener('click', function() {
if (elevator.alarmActive) return;
if (!elevator.isMoving && !elevator.doorsOpen) {
openDoors();
}
});
doorCloseButton.addEventListener('click', function() {
if (elevator.alarmActive) return;
if (!elevator.isMoving && elevator.doorsOpen) {
closeDoors();
}
});
// Elevator logic
function determineDirection() {
if (elevator.targetFloors.length === 0) {
elevator.direction = 'idle';
return;
}
// Sort targets based on current direction
if (elevator.direction === 'up' ||
(elevator.direction === 'idle' && elevator.targetFloors.some(f => f > elevator.currentFloor))) {
elevator.direction = 'up';
elevator.targetFloors.sort((a, b) => a - b); // ascending
} else {
elevator.direction = 'down';
elevator.targetFloors.sort((a, b) => b - a); // descending
}
updateDisplay();
}
function moveToNextFloor() {
if (elevator.targetFloors.length === 0) {
elevator.direction = 'idle';
updateStatus('Elevator idle');
updateDisplay();
return;
}
const nextFloor = elevator.targetFloors[0];
// Check if we need to change direction
if ((elevator.direction === 'up' && nextFloor < elevator.currentFloor) ||
(elevator.direction === 'down' && nextFloor > elevator.currentFloor)) {
// Reset all buttons in opposite direction
resetOppositeDirectionButtons();
determineDirection();
return moveToNextFloor();
}
// Calculate time based on floor difference (1 second per floor)
const floorDifference = Math.abs(nextFloor - elevator.currentFloor);
const moveTime = floorDifference * 1000; // 1 second per floor
elevator.isMoving = true;
updateStatus(`Moving ${elevator.direction} to floor ${nextFloor}`);
// Start floor display animation
startFloorAnimation(elevator.currentFloor, nextFloor, moveTime);
// Play moving sound
elevator.movingSound.currentTime = 0;
elevator.movingSound.play();
// Add moving animation class
movingPattern.classList.add(elevator.direction === 'up' ? 'moving-up' : 'moving-down');
// Simulate movement
setTimeout(() => {
elevator.currentFloor = nextFloor;
elevator.targetFloors.shift();
// Stop floor animation
stopFloorAnimation();
// Remove active class from button
document.querySelector(`.elevator-button[data-floor="${nextFloor}"]`).classList.remove('active');
// Stop moving sound
elevator.movingSound.pause();
// Remove moving animation
movingPattern.classList.remove('moving-up', 'moving-down');
// Play floor reached sound
elevator.floorReachedSound.currentTime = 0;
elevator.floorReachedSound.play();
// Update display
updateDisplay();
updateStatus(`Arrived at floor ${nextFloor}`);
// Wait 500ms before opening doors
setTimeout(() => {
// Open doors
openDoors();
// After 2 seconds, close doors
setTimeout(() => {
closeDoors();
setTimeout(() => {
elevator.isMoving = false;
moveToNextFloor();
}, 500);
}, 2000);
}, 500);
}, moveTime);
}
function startFloorAnimation(currentFloor, targetFloor, duration) {
const start = currentFloor;
const end = targetFloor;
const steps = Math.abs(end - start);
const stepTime = duration / steps;
let step = 0;
clearInterval(elevator.floorChangeInterval);
elevator.floorChangeInterval = setInterval(() => {
if (elevator.direction === 'up') {
floorDisplay.textContent = start + Math.floor((end - start) * (step / steps));
step++;
} else {
floorDisplay.textContent = start - Math.floor((start - end) * (step / steps));
step++;
}
if (step >= steps) {
clearInterval(elevator.floorChangeInterval);
}
}, stepTime);
}
function stopFloorAnimation() {
clearInterval(elevator.floorChangeInterval);
floorDisplay.textContent = elevator.currentFloor;
}
function openDoors() {
if (elevator.doorsOpen) return;
elevator.doorsOpen = true;
doorsContainer.classList.add('doors-open');
// Play door open sound
elevator.doorOpenSound.currentTime = 0;
elevator.doorOpenSound.play();
updateStatus('Doors opening');
}
function closeDoors() {
if (!elevator.doorsOpen) return;
elevator.doorsOpen = false;
doorsContainer.classList.remove('doors-open');
// Play door close sound
elevator.doorCloseSound.currentTime = 0;
elevator.doorCloseSound.play();
updateStatus('Doors closing');
}
function resetOppositeDirectionButtons() {
const oppositeDirection = elevator.direction === 'up' ? 'down' : 'up';
// Remove targets in opposite direction
if (oppositeDirection === 'up') {
elevator.targetFloors = elevator.targetFloors.filter(f => f <= elevator.currentFloor);
} else {
elevator.targetFloors = elevator.targetFloors.filter(f => f >= elevator.currentFloor);
}
// Update button states
elevatorButtons.forEach(button => {
const floor = parseInt(button.dataset.floor);
if ((oppositeDirection === 'up' && floor > elevator.currentFloor) ||
(oppositeDirection === 'down' && floor < elevator.currentFloor)) {
button.classList.remove('active');
}
});
updateStatus(`Changed direction to ${elevator.direction}`);
}
function emergencyStop() {
elevator.isMoving = false;
elevator.targetFloors = [];
elevator.movingSound.pause();
movingPattern.classList.remove('moving-up', 'moving-down');
stopFloorAnimation();
// Reset all buttons
elevatorButtons.forEach(button => button.classList.remove('active'));
updateStatus('EMERGENCY STOP!');
// Open doors if not already open
if (!elevator.doorsOpen) {
openDoors();
}
}
function resetElevator() {
emergencyStop();
elevator.currentFloor = 1;
elevator.direction = 'idle';
updateDisplay();
updateStatus('Elevator reset to ground floor');
}
function updateDisplay() {
floorDisplay.textContent = elevator.currentFloor;
// Update direction arrows (only show one at a time)
if (elevator.direction === 'up') {
upArrow.classList.add('active');
downArrow.classList.remove('active');
} else if (elevator.direction === 'down') {
downArrow.classList.add('active');
upArrow.classList.remove('active');
} else {
upArrow.classList.remove('active');
downArrow.classList.remove('active');
}
}
function updateStatus(message) {
statusMessage.textContent = message;
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=szsheep/elevator-sim" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>