Spaces:
Running
Running
Add 2 files
Browse files- README.md +7 -5
- index.html +533 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: elevator-sim
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,533 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Elevator Simulator</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<style>
|
| 9 |
+
@import url('https://fonts.googleapis.com/css2?family=Digital+7&display=swap');
|
| 10 |
+
|
| 11 |
+
.elevator-door {
|
| 12 |
+
transition: all 1s ease-in-out;
|
| 13 |
+
position: relative;
|
| 14 |
+
z-index: 10;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
.doors-open .door-left {
|
| 18 |
+
transform: translateX(-100%);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.doors-open .door-right {
|
| 22 |
+
transform: translateX(100%);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.elevator-button {
|
| 26 |
+
transition: all 0.2s ease;
|
| 27 |
+
aspect-ratio: 1/1;
|
| 28 |
+
display: flex;
|
| 29 |
+
align-items: center;
|
| 30 |
+
justify-content: center;
|
| 31 |
+
width: 100%;
|
| 32 |
+
min-width: 60px;
|
| 33 |
+
font-size: 1.5rem;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.control-button {
|
| 37 |
+
transition: all 0.2s ease;
|
| 38 |
+
display: flex;
|
| 39 |
+
align-items: center;
|
| 40 |
+
justify-content: center;
|
| 41 |
+
width: 100%;
|
| 42 |
+
font-size: 0.9rem;
|
| 43 |
+
padding: 0.5rem;
|
| 44 |
+
height: auto;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.elevator-button.active {
|
| 48 |
+
background-color: #ffcc00;
|
| 49 |
+
box-shadow: 0 0 15px #ffcc00;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.seven-segment {
|
| 53 |
+
font-family: 'Digital 7', sans-serif;
|
| 54 |
+
color: #ff0000;
|
| 55 |
+
text-shadow: 0 0 5px #ff0000;
|
| 56 |
+
font-size: 4rem;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.floor-indicator {
|
| 60 |
+
transition: all 0.5s ease;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
@keyframes moveUp {
|
| 64 |
+
0% { transform: translateY(0); }
|
| 65 |
+
100% { transform: translateY(-100%); }
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
@keyframes moveDown {
|
| 69 |
+
0% { transform: translateY(0); }
|
| 70 |
+
100% { transform: translateY(100%); }
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.moving-up {
|
| 74 |
+
animation: moveUp 1s linear infinite;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.moving-down {
|
| 78 |
+
animation: moveDown 1s linear infinite;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
.control-panel {
|
| 82 |
+
scrollbar-width: none;
|
| 83 |
+
-ms-overflow-style: none;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.control-panel::-webkit-scrollbar {
|
| 87 |
+
display: none;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.floor-display-container {
|
| 91 |
+
height: 100px;
|
| 92 |
+
background-color: #111;
|
| 93 |
+
border-radius: 8px;
|
| 94 |
+
display: flex;
|
| 95 |
+
align-items: center;
|
| 96 |
+
justify-content: center;
|
| 97 |
+
padding: 0 20px;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
.direction-arrow {
|
| 101 |
+
font-size: 3rem;
|
| 102 |
+
margin-left: 20px;
|
| 103 |
+
opacity: 0;
|
| 104 |
+
transition: opacity 0.3s ease;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.direction-arrow.active {
|
| 108 |
+
opacity: 1;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.up-arrow {
|
| 112 |
+
color: #ff0000;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.down-arrow {
|
| 116 |
+
color: #0066ff;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.button-gap {
|
| 120 |
+
margin-bottom: 1rem;
|
| 121 |
+
}
|
| 122 |
+
</style>
|
| 123 |
+
</head>
|
| 124 |
+
<body class="bg-gray-900 min-h-screen flex items-center justify-center p-4">
|
| 125 |
+
<div class="relative bg-gray-800 rounded-xl p-6 shadow-2xl w-full max-w-4xl">
|
| 126 |
+
<h1 class="text-4xl font-bold text-center text-white mb-6">Elevator Simulator</h1>
|
| 127 |
+
|
| 128 |
+
<div class="flex flex-col md:flex-row gap-6">
|
| 129 |
+
<!-- Elevator shaft with doors -->
|
| 130 |
+
<div class="w-full md:w-2/3 relative h-[600px] bg-gray-700 rounded-xl overflow-hidden">
|
| 131 |
+
<!-- Floor indicator strip -->
|
| 132 |
+
<div class="absolute left-0 right-0 top-0 h-24 bg-gray-900 flex justify-center items-center px-6">
|
| 133 |
+
<div class="floor-display-container">
|
| 134 |
+
<div class="seven-segment font-bold" id="floor-display">1</div>
|
| 135 |
+
<div class="direction-arrow up-arrow" id="up-arrow">↑</div>
|
| 136 |
+
<div class="direction-arrow down-arrow" id="down-arrow">↓</div>
|
| 137 |
+
</div>
|
| 138 |
+
</div>
|
| 139 |
+
|
| 140 |
+
<!-- Elevator doors -->
|
| 141 |
+
<div class="absolute bottom-0 left-0 right-0 h-[480px] bg-gray-600 flex">
|
| 142 |
+
<div class="elevator-door door-left w-1/2 h-full bg-gray-500 border-r-2 border-gray-700"></div>
|
| 143 |
+
<div class="elevator-door door-right w-1/2 h-full bg-gray-500 border-l-2 border-gray-700"></div>
|
| 144 |
+
</div>
|
| 145 |
+
|
| 146 |
+
<!-- Elevator interior -->
|
| 147 |
+
<div class="absolute bottom-0 left-0 right-0 h-[480px] bg-gray-400 flex items-center justify-center">
|
| 148 |
+
<div class="text-gray-700 font-bold text-2xl">Welcome!</div>
|
| 149 |
+
</div>
|
| 150 |
+
|
| 151 |
+
<!-- Moving pattern for animation -->
|
| 152 |
+
<div class="absolute top-24 left-0 right-0 h-[480px] overflow-hidden">
|
| 153 |
+
<div class="h-full w-full relative" id="moving-pattern">
|
| 154 |
+
<div class="absolute top-0 left-0 right-0 h-full bg-gray-600"></div>
|
| 155 |
+
<div class="absolute top-full left-0 right-0 h-full bg-gray-600"></div>
|
| 156 |
+
<div class="absolute top-0 left-0 right-0 h-full bg-gray-600 floor-indicator" id="floor-indicator"></div>
|
| 157 |
+
</div>
|
| 158 |
+
</div>
|
| 159 |
+
</div>
|
| 160 |
+
|
| 161 |
+
<!-- Elevator control panel -->
|
| 162 |
+
<div class="w-full md:w-1/3">
|
| 163 |
+
<div class="bg-gray-700 rounded-xl p-6 h-[600px] overflow-y-auto control-panel">
|
| 164 |
+
<div class="grid grid-cols-4 gap-4">
|
| 165 |
+
<!-- Floor buttons -->
|
| 166 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="16">16</button>
|
| 167 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="15">15</button>
|
| 168 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="14">14</button>
|
| 169 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="13">13</button>
|
| 170 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="12">12</button>
|
| 171 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="11">11</button>
|
| 172 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="10">10</button>
|
| 173 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="9">9</button>
|
| 174 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="8">8</button>
|
| 175 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="7">7</button>
|
| 176 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="6">6</button>
|
| 177 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="5">5</button>
|
| 178 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="4">4</button>
|
| 179 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="3">3</button>
|
| 180 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="2">2</button>
|
| 181 |
+
<button class="elevator-button bg-gray-300 rounded-lg text-black font-bold" data-floor="1">1</button>
|
| 182 |
+
|
| 183 |
+
<!-- Bigger gap before control buttons -->
|
| 184 |
+
<div class="col-span-4 button-gap"></div>
|
| 185 |
+
|
| 186 |
+
<!-- Control buttons -->
|
| 187 |
+
<button class="control-button bg-red-500 rounded-lg text-white font-bold col-span-2" id="emergency">EMERGENCY</button>
|
| 188 |
+
<button class="control-button bg-yellow-500 rounded-lg text-black font-bold col-span-2" id="door-open">DOOR OPEN</button>
|
| 189 |
+
<button class="control-button bg-yellow-500 rounded-lg text-black font-bold col-span-2" id="door-close">DOOR CLOSE</button>
|
| 190 |
+
<button class="control-button bg-green-500 rounded-lg text-black font-bold col-span-2" id="alarm">ALARM</button>
|
| 191 |
+
</div>
|
| 192 |
+
</div>
|
| 193 |
+
</div>
|
| 194 |
+
</div>
|
| 195 |
+
|
| 196 |
+
<div class="mt-6 text-white">
|
| 197 |
+
<h2 class="font-bold text-2xl mb-3">Elevator Status:</h2>
|
| 198 |
+
<div id="status-message" class="bg-gray-700 p-4 rounded-lg text-xl">Ready</div>
|
| 199 |
+
</div>
|
| 200 |
+
</div>
|
| 201 |
+
|
| 202 |
+
<audio id="door-open-sound" src="https://www.soundjay.com/mechanical/sounds/elevator-door-open-01.mp3" preload="auto"></audio>
|
| 203 |
+
<audio id="door-close-sound" src="https://www.soundjay.com/mechanical/sounds/elevator-door-close-01.mp3" preload="auto"></audio>
|
| 204 |
+
<audio id="floor-reached-sound" src="https://www.soundjay.com/mechanical/sounds/elevator-ding-01.mp3" preload="auto"></audio>
|
| 205 |
+
<audio id="moving-sound" src="https://www.soundjay.com/mechanical/sounds/elevator-move-01.mp3" preload="auto"></audio>
|
| 206 |
+
<audio id="alarm-sound" src="https://www.soundjay.com/mechanical/sounds/siren-01.mp3" preload="auto"></audio>
|
| 207 |
+
|
| 208 |
+
<script>
|
| 209 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 210 |
+
// Elevator state
|
| 211 |
+
const elevator = {
|
| 212 |
+
currentFloor: 1,
|
| 213 |
+
targetFloors: [],
|
| 214 |
+
direction: 'idle', // 'up', 'down', 'idle'
|
| 215 |
+
isMoving: false,
|
| 216 |
+
doorsOpen: false,
|
| 217 |
+
movingSound: document.getElementById('moving-sound'),
|
| 218 |
+
doorOpenSound: document.getElementById('door-open-sound'),
|
| 219 |
+
doorCloseSound: document.getElementById('door-close-sound'),
|
| 220 |
+
floorReachedSound: document.getElementById('floor-reached-sound'),
|
| 221 |
+
alarmSound: document.getElementById('alarm-sound'),
|
| 222 |
+
floorChangeInterval: null,
|
| 223 |
+
alarmActive: false
|
| 224 |
+
};
|
| 225 |
+
|
| 226 |
+
// DOM elements
|
| 227 |
+
const floorDisplay = document.getElementById('floor-display');
|
| 228 |
+
const upArrow = document.getElementById('up-arrow');
|
| 229 |
+
const downArrow = document.getElementById('down-arrow');
|
| 230 |
+
const statusMessage = document.getElementById('status-message');
|
| 231 |
+
const floorIndicator = document.getElementById('floor-indicator');
|
| 232 |
+
const movingPattern = document.getElementById('moving-pattern');
|
| 233 |
+
const doorLeft = document.querySelector('.door-left');
|
| 234 |
+
const doorRight = document.querySelector('.door-right');
|
| 235 |
+
const doorsContainer = document.querySelector('.bg-gray-600.flex');
|
| 236 |
+
const elevatorButtons = document.querySelectorAll('.elevator-button[data-floor]');
|
| 237 |
+
const emergencyButton = document.getElementById('emergency');
|
| 238 |
+
const doorOpenButton = document.getElementById('door-open');
|
| 239 |
+
const doorCloseButton = document.getElementById('door-close');
|
| 240 |
+
const alarmButton = document.getElementById('alarm');
|
| 241 |
+
|
| 242 |
+
// Initialize
|
| 243 |
+
updateDisplay();
|
| 244 |
+
|
| 245 |
+
// Event listeners for floor buttons
|
| 246 |
+
elevatorButtons.forEach(button => {
|
| 247 |
+
button.addEventListener('click', function() {
|
| 248 |
+
if (elevator.alarmActive) return;
|
| 249 |
+
|
| 250 |
+
const floor = parseInt(this.dataset.floor);
|
| 251 |
+
if (!elevator.targetFloors.includes(floor) && floor !== elevator.currentFloor) {
|
| 252 |
+
elevator.targetFloors.push(floor);
|
| 253 |
+
this.classList.add('active');
|
| 254 |
+
updateStatus(`Floor ${floor} added to queue`);
|
| 255 |
+
|
| 256 |
+
// If elevator is idle, start moving
|
| 257 |
+
if (elevator.direction === 'idle') {
|
| 258 |
+
determineDirection();
|
| 259 |
+
moveToNextFloor();
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
});
|
| 263 |
+
});
|
| 264 |
+
|
| 265 |
+
// Emergency button
|
| 266 |
+
emergencyButton.addEventListener('click', function() {
|
| 267 |
+
if (elevator.isMoving) {
|
| 268 |
+
emergencyStop();
|
| 269 |
+
} else {
|
| 270 |
+
resetElevator();
|
| 271 |
+
}
|
| 272 |
+
});
|
| 273 |
+
|
| 274 |
+
// Alarm button
|
| 275 |
+
alarmButton.addEventListener('click', function() {
|
| 276 |
+
if (elevator.alarmActive) {
|
| 277 |
+
// Stop alarm
|
| 278 |
+
elevator.alarmSound.pause();
|
| 279 |
+
elevator.alarmActive = false;
|
| 280 |
+
this.classList.remove('bg-red-500');
|
| 281 |
+
this.classList.add('bg-green-500');
|
| 282 |
+
updateStatus('Alarm deactivated');
|
| 283 |
+
} else {
|
| 284 |
+
// Start alarm
|
| 285 |
+
elevator.alarmSound.currentTime = 0;
|
| 286 |
+
elevator.alarmSound.loop = true;
|
| 287 |
+
elevator.alarmSound.play();
|
| 288 |
+
elevator.alarmActive = true;
|
| 289 |
+
this.classList.remove('bg-green-500');
|
| 290 |
+
this.classList.add('bg-red-500');
|
| 291 |
+
updateStatus('ALARM ACTIVATED!');
|
| 292 |
+
}
|
| 293 |
+
});
|
| 294 |
+
|
| 295 |
+
// Door controls
|
| 296 |
+
doorOpenButton.addEventListener('click', function() {
|
| 297 |
+
if (elevator.alarmActive) return;
|
| 298 |
+
if (!elevator.isMoving && !elevator.doorsOpen) {
|
| 299 |
+
openDoors();
|
| 300 |
+
}
|
| 301 |
+
});
|
| 302 |
+
|
| 303 |
+
doorCloseButton.addEventListener('click', function() {
|
| 304 |
+
if (elevator.alarmActive) return;
|
| 305 |
+
if (!elevator.isMoving && elevator.doorsOpen) {
|
| 306 |
+
closeDoors();
|
| 307 |
+
}
|
| 308 |
+
});
|
| 309 |
+
|
| 310 |
+
// Elevator logic
|
| 311 |
+
function determineDirection() {
|
| 312 |
+
if (elevator.targetFloors.length === 0) {
|
| 313 |
+
elevator.direction = 'idle';
|
| 314 |
+
return;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
// Sort targets based on current direction
|
| 318 |
+
if (elevator.direction === 'up' ||
|
| 319 |
+
(elevator.direction === 'idle' && elevator.targetFloors.some(f => f > elevator.currentFloor))) {
|
| 320 |
+
elevator.direction = 'up';
|
| 321 |
+
elevator.targetFloors.sort((a, b) => a - b); // ascending
|
| 322 |
+
} else {
|
| 323 |
+
elevator.direction = 'down';
|
| 324 |
+
elevator.targetFloors.sort((a, b) => b - a); // descending
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
updateDisplay();
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
function moveToNextFloor() {
|
| 331 |
+
if (elevator.targetFloors.length === 0) {
|
| 332 |
+
elevator.direction = 'idle';
|
| 333 |
+
updateStatus('Elevator idle');
|
| 334 |
+
updateDisplay();
|
| 335 |
+
return;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
const nextFloor = elevator.targetFloors[0];
|
| 339 |
+
|
| 340 |
+
// Check if we need to change direction
|
| 341 |
+
if ((elevator.direction === 'up' && nextFloor < elevator.currentFloor) ||
|
| 342 |
+
(elevator.direction === 'down' && nextFloor > elevator.currentFloor)) {
|
| 343 |
+
// Reset all buttons in opposite direction
|
| 344 |
+
resetOppositeDirectionButtons();
|
| 345 |
+
determineDirection();
|
| 346 |
+
return moveToNextFloor();
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
// Calculate time based on floor difference (1 second per floor)
|
| 350 |
+
const floorDifference = Math.abs(nextFloor - elevator.currentFloor);
|
| 351 |
+
const moveTime = floorDifference * 1000; // 1 second per floor
|
| 352 |
+
|
| 353 |
+
elevator.isMoving = true;
|
| 354 |
+
updateStatus(`Moving ${elevator.direction} to floor ${nextFloor}`);
|
| 355 |
+
|
| 356 |
+
// Start floor display animation
|
| 357 |
+
startFloorAnimation(elevator.currentFloor, nextFloor, moveTime);
|
| 358 |
+
|
| 359 |
+
// Play moving sound
|
| 360 |
+
elevator.movingSound.currentTime = 0;
|
| 361 |
+
elevator.movingSound.play();
|
| 362 |
+
|
| 363 |
+
// Add moving animation class
|
| 364 |
+
movingPattern.classList.add(elevator.direction === 'up' ? 'moving-up' : 'moving-down');
|
| 365 |
+
|
| 366 |
+
// Simulate movement
|
| 367 |
+
setTimeout(() => {
|
| 368 |
+
elevator.currentFloor = nextFloor;
|
| 369 |
+
elevator.targetFloors.shift();
|
| 370 |
+
|
| 371 |
+
// Stop floor animation
|
| 372 |
+
stopFloorAnimation();
|
| 373 |
+
|
| 374 |
+
// Remove active class from button
|
| 375 |
+
document.querySelector(`.elevator-button[data-floor="${nextFloor}"]`).classList.remove('active');
|
| 376 |
+
|
| 377 |
+
// Stop moving sound
|
| 378 |
+
elevator.movingSound.pause();
|
| 379 |
+
|
| 380 |
+
// Remove moving animation
|
| 381 |
+
movingPattern.classList.remove('moving-up', 'moving-down');
|
| 382 |
+
|
| 383 |
+
// Play floor reached sound
|
| 384 |
+
elevator.floorReachedSound.currentTime = 0;
|
| 385 |
+
elevator.floorReachedSound.play();
|
| 386 |
+
|
| 387 |
+
// Update display
|
| 388 |
+
updateDisplay();
|
| 389 |
+
updateStatus(`Arrived at floor ${nextFloor}`);
|
| 390 |
+
|
| 391 |
+
// Wait 500ms before opening doors
|
| 392 |
+
setTimeout(() => {
|
| 393 |
+
// Open doors
|
| 394 |
+
openDoors();
|
| 395 |
+
|
| 396 |
+
// After 2 seconds, close doors
|
| 397 |
+
setTimeout(() => {
|
| 398 |
+
closeDoors();
|
| 399 |
+
setTimeout(() => {
|
| 400 |
+
elevator.isMoving = false;
|
| 401 |
+
moveToNextFloor();
|
| 402 |
+
}, 500);
|
| 403 |
+
}, 2000);
|
| 404 |
+
}, 500);
|
| 405 |
+
}, moveTime);
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
function startFloorAnimation(currentFloor, targetFloor, duration) {
|
| 409 |
+
const start = currentFloor;
|
| 410 |
+
const end = targetFloor;
|
| 411 |
+
const steps = Math.abs(end - start);
|
| 412 |
+
const stepTime = duration / steps;
|
| 413 |
+
let step = 0;
|
| 414 |
+
|
| 415 |
+
clearInterval(elevator.floorChangeInterval);
|
| 416 |
+
|
| 417 |
+
elevator.floorChangeInterval = setInterval(() => {
|
| 418 |
+
if (elevator.direction === 'up') {
|
| 419 |
+
floorDisplay.textContent = start + Math.floor((end - start) * (step / steps));
|
| 420 |
+
step++;
|
| 421 |
+
} else {
|
| 422 |
+
floorDisplay.textContent = start - Math.floor((start - end) * (step / steps));
|
| 423 |
+
step++;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
if (step >= steps) {
|
| 427 |
+
clearInterval(elevator.floorChangeInterval);
|
| 428 |
+
}
|
| 429 |
+
}, stepTime);
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
function stopFloorAnimation() {
|
| 433 |
+
clearInterval(elevator.floorChangeInterval);
|
| 434 |
+
floorDisplay.textContent = elevator.currentFloor;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
function openDoors() {
|
| 438 |
+
if (elevator.doorsOpen) return;
|
| 439 |
+
|
| 440 |
+
elevator.doorsOpen = true;
|
| 441 |
+
doorsContainer.classList.add('doors-open');
|
| 442 |
+
|
| 443 |
+
// Play door open sound
|
| 444 |
+
elevator.doorOpenSound.currentTime = 0;
|
| 445 |
+
elevator.doorOpenSound.play();
|
| 446 |
+
|
| 447 |
+
updateStatus('Doors opening');
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
function closeDoors() {
|
| 451 |
+
if (!elevator.doorsOpen) return;
|
| 452 |
+
|
| 453 |
+
elevator.doorsOpen = false;
|
| 454 |
+
doorsContainer.classList.remove('doors-open');
|
| 455 |
+
|
| 456 |
+
// Play door close sound
|
| 457 |
+
elevator.doorCloseSound.currentTime = 0;
|
| 458 |
+
elevator.doorCloseSound.play();
|
| 459 |
+
|
| 460 |
+
updateStatus('Doors closing');
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
function resetOppositeDirectionButtons() {
|
| 464 |
+
const oppositeDirection = elevator.direction === 'up' ? 'down' : 'up';
|
| 465 |
+
|
| 466 |
+
// Remove targets in opposite direction
|
| 467 |
+
if (oppositeDirection === 'up') {
|
| 468 |
+
elevator.targetFloors = elevator.targetFloors.filter(f => f <= elevator.currentFloor);
|
| 469 |
+
} else {
|
| 470 |
+
elevator.targetFloors = elevator.targetFloors.filter(f => f >= elevator.currentFloor);
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
// Update button states
|
| 474 |
+
elevatorButtons.forEach(button => {
|
| 475 |
+
const floor = parseInt(button.dataset.floor);
|
| 476 |
+
if ((oppositeDirection === 'up' && floor > elevator.currentFloor) ||
|
| 477 |
+
(oppositeDirection === 'down' && floor < elevator.currentFloor)) {
|
| 478 |
+
button.classList.remove('active');
|
| 479 |
+
}
|
| 480 |
+
});
|
| 481 |
+
|
| 482 |
+
updateStatus(`Changed direction to ${elevator.direction}`);
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
function emergencyStop() {
|
| 486 |
+
elevator.isMoving = false;
|
| 487 |
+
elevator.targetFloors = [];
|
| 488 |
+
elevator.movingSound.pause();
|
| 489 |
+
movingPattern.classList.remove('moving-up', 'moving-down');
|
| 490 |
+
stopFloorAnimation();
|
| 491 |
+
|
| 492 |
+
// Reset all buttons
|
| 493 |
+
elevatorButtons.forEach(button => button.classList.remove('active'));
|
| 494 |
+
|
| 495 |
+
updateStatus('EMERGENCY STOP!');
|
| 496 |
+
|
| 497 |
+
// Open doors if not already open
|
| 498 |
+
if (!elevator.doorsOpen) {
|
| 499 |
+
openDoors();
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
function resetElevator() {
|
| 504 |
+
emergencyStop();
|
| 505 |
+
elevator.currentFloor = 1;
|
| 506 |
+
elevator.direction = 'idle';
|
| 507 |
+
updateDisplay();
|
| 508 |
+
updateStatus('Elevator reset to ground floor');
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
function updateDisplay() {
|
| 512 |
+
floorDisplay.textContent = elevator.currentFloor;
|
| 513 |
+
|
| 514 |
+
// Update direction arrows (only show one at a time)
|
| 515 |
+
if (elevator.direction === 'up') {
|
| 516 |
+
upArrow.classList.add('active');
|
| 517 |
+
downArrow.classList.remove('active');
|
| 518 |
+
} else if (elevator.direction === 'down') {
|
| 519 |
+
downArrow.classList.add('active');
|
| 520 |
+
upArrow.classList.remove('active');
|
| 521 |
+
} else {
|
| 522 |
+
upArrow.classList.remove('active');
|
| 523 |
+
downArrow.classList.remove('active');
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
function updateStatus(message) {
|
| 528 |
+
statusMessage.textContent = message;
|
| 529 |
+
}
|
| 530 |
+
});
|
| 531 |
+
</script>
|
| 532 |
+
<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>
|
| 533 |
+
</html>
|