diff --git a/Lift-Problem-Demo.mov b/Lift-Problem-Demo.mov deleted file mode 100644 index 37c5865d..00000000 Binary files a/Lift-Problem-Demo.mov and /dev/null differ diff --git a/Lift-Simulation-Example.png b/Lift-Simulation-Example.png deleted file mode 100644 index 2eef4f8e..00000000 Binary files a/Lift-Simulation-Example.png and /dev/null differ diff --git a/README.md b/README.md index bd506176..ec2115e2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Lift-Simulation +https://liftsimulator-project.netlify.app/ Create a web app where you can simulate lift mechanics for a client - # UI Example ![Lift Simulation Example](Lift-Simulation-Example.png "Lift Simulation Example") diff --git a/css/main.css b/css/main.css new file mode 100644 index 00000000..5ab79e54 --- /dev/null +++ b/css/main.css @@ -0,0 +1,114 @@ +body { + font-family: "Karla", sans-serif; + margin: 5%; + background-image: url("../images/citybackground.jpg"); + background-repeat: no-repeat; + background-attachment: fixed; + background-size: cover; +} + +.center { + border: 5px solid skyblue; + padding: 5%; + margin-top: 15%; + margin-left: 25%; + margin-right: 25%; + margin-bottom: 15%; + text-align: center; + backdrop-filter: blur(50px); + /* font-size: 25px; */ +} + +.building { + display: flex; + flex:1; + justify-content: flex-start; + backdrop-filter: blur(50px); + border: 5px solid black; +} + +.buildinginfo { + border: 5px solid skyblue; + margin-bottom:50px; + margin-left: 25%; + margin-right: 25%; + text-align: center; + backdrop-filter: blur(50px); +} + +.floor { + display: flex; + padding: 10px 5px 2px 10px; /* Add margin/padding as needed */ + border: 2px solid black; + background-color: #f0f0f0; + font-size: 29px; + font-weight: 600; + height: 80px; + background-image: url("../images/bricktexture.jpg"); + /* background-repeat: no-repeat; */ + /* background-attachment: fixed; */ + background-size: cover; + +} +.floor-images { + margin-left: 40px; + display: flex; + justify-content: flex-start; + gap: 40px; + opacity: 1; + } + +.floorimages-div { + /* border: 2px solid blueviolet; */ + /*needed for the debugging*/ + width: 50px; + } +.direction-image { + border: 4px solid black; + background-color: white; + padding: 2px; + border-radius: 35%; + margin-bottom: 5px; + +} +.floor-number{ + margin-left: auto; + border: 1px solid black; + padding-top: 10px; + background-color: skyblue; + border-radius: 15%; + margin-bottom: 5px; +} +.lift-image { + width : 60px; + height: 75px; + /* border : 4px solid red; */ + border-radius: 10%; +} + +/* CSS for lift transition animation */ +.transition-animation { + transition : ease-in 5s; +} +/* for the elevator open close animation */ +.elevator { + position: relative; + width : 60px; + height: 75px; + display: flex; + overflow: hidden; +} +.door { + position: absolute; + width: 50%; + height: 100%; + transition: transform 0.5s ease-in-out; +} +#leftDoor { + left: 0; + transform-origin: left; +} +#rightDoor { + right: 0; + transform-origin: right; +} diff --git a/elevators.html b/elevators.html new file mode 100644 index 00000000..4a899edd --- /dev/null +++ b/elevators.html @@ -0,0 +1,34 @@ + + + + Elevators Page + + + + +
+

Elevators Page

+
+
+

Building with the Lifts

+
+ +
+ + + + diff --git a/images/bricktexture.jpg b/images/bricktexture.jpg new file mode 100644 index 00000000..ec45cb2b Binary files /dev/null and b/images/bricktexture.jpg differ diff --git a/images/citybackground.jpg b/images/citybackground.jpg new file mode 100644 index 00000000..125f5fa2 Binary files /dev/null and b/images/citybackground.jpg differ diff --git a/images/lift-image.jpg b/images/lift-image.jpg new file mode 100644 index 00000000..1002e325 Binary files /dev/null and b/images/lift-image.jpg differ diff --git a/images/up-down.png b/images/up-down.png new file mode 100644 index 00000000..e035745e Binary files /dev/null and b/images/up-down.png differ diff --git a/index.html b/index.html new file mode 100644 index 00000000..0e73eeca --- /dev/null +++ b/index.html @@ -0,0 +1,39 @@ + + + + Lift-Simulator + + + +
+

Lift-Simulator

+

Please provide the following information:

+ +
+ + (Minimum 1 or Maximum 50 )

+ + + (Minimum 1 or Maximum 5 )

+ + +
+
+ + + + diff --git a/js/elevators.js b/js/elevators.js new file mode 100644 index 00000000..b5000406 --- /dev/null +++ b/js/elevators.js @@ -0,0 +1,220 @@ +// Function to get query parameters from the URL +function getQueryParams() { + const params = new URLSearchParams(window.location.search); + return { + floors: params.get("floors"), + elevators: params.get("elevators"), + }; +} + +// Get query parameters +const { floors, elevators } = getQueryParams(); + +// Initialize a variable to keep track of the last floor with a lift image +let lastLiftFloor = null; + +// Display the values +document.getElementById( + "floorsDisplay" +).textContent = `Number of Floors: ${floors}`; +document.getElementById( + "elevatorsDisplay" +).textContent = `Number of Elevators Needed: ${elevators}`; + +// Select the container where you want to generate the floors +const buildingContainer = document.getElementById("building"); + +var liftStates = {}; +for(let i=1; i<=elevators; i++) { + liftStates[`lift_${i}`] = 1; +} + +const dataStore = { + username:"creator", + no_of_floor: floors, + no_of_elevators: elevators, + state_of_lifts: liftStates, +}; + +var liftNumber = 1; + +var divFloor = 0; + +// Function to generate a floor with an image +function generateFloor(floorNumber, imageSource) { + // Create a
element for the floor + const floor = document.createElement("div"); + floor.className = "floor"; // You can add CSS classes for styling + + // Create a
element for the floor + const floorImages = document.createElement("div"); + + floorImages.className = "floor-images"; // You can add CSS classes for styling + + // Add an element to the floor + const directionImage = document.createElement("img"); + directionImage.src = "/images/up-down.png"; // Provide the URL to your PNG image + + directionImage.className = "direction-image"; + + //experiment code to add lift on a certain floor + directionImage.addEventListener("click", (event) => { + //getting the current floor id + const currFloorId = event.target.parentNode.id; + // console.log("current floorId: ", currFloorId); + + // Get the div element by its ID (you can use any other method to select the div) + var selectedFloorImagesDiv = document + .getElementById(`${currFloorId}`) + .querySelector(".floor-images"); + // console.log("parent div", selectedFloorImagesDiv.children); + var LiftImage = document.getElementById(`liftImage${liftNumber}`); + // console.log(LiftImage.querySelector('#leftDoor')) + const liftColumn = selectedFloorImagesDiv.children[liftNumber - 1]; + const lastFloor = LiftImage.getAttribute("floordetail"); + // console.log("last Floor = ", lastFloor); + + var animationTime = Math.abs(floorNumber - lastFloor) * 2; + // console.log(animationTime); + + LiftImage.setAttribute("floorDetail", `${floorNumber}`); // Adding a custom attribute + const liftcurrfloornumber = LiftImage.getAttribute('floordetail'); + const liftcurridnumber = LiftImage.getAttribute('liftid'); + // console.log(LiftImage.getAttribute('floordetail')); + // console.log(LiftImage.getAttribute('liftid')) + //updating datastore for updated lift information + dataStore.state_of_lifts[`lift_${liftcurridnumber}`] = liftcurrfloornumber; + // console.log("updated datastore = ", dataStore); + // LiftImage.classList.add("transition-animation"); + LiftImage.style.transition = `ease-in ${animationTime}s`; + // setTimeout(()=>{}, animationTime*1000) + // console.log(liftColumn); + liftNumber += 1; + if (liftNumber > elevators) { + liftNumber = 1; + } + // console.log("liftImage = " , firstLiftImage); + // console.log("liftNumber = ", liftNumber) + + // var howTop = 0; + + // const left = liftColumn.offsetLeft; + const top = liftColumn.offsetTop; + + const leftDoor = LiftImage.querySelector('#leftDoor'); + const rightDoor = LiftImage.querySelector('#rightDoor'); + + function openDoors() { + leftDoor.style.transform = 'translateX(-100%)'; + rightDoor.style.transform = 'translateX(100%)'; + setTimeout(closeDoors, 2500); + } + + function closeDoors() { + leftDoor.style.transform = 'translateX(0)'; + rightDoor.style.transform = 'translateX(0)'; + } + + // Example: Open the doors after 2 seconds and close them after 5 seconds + setTimeout(openDoors, animationTime*1000+2500); + + // console.log(left, top); + // LiftImage.style.left = (howLeft*liftNumber) + "px"; + LiftImage.style.top = top + "px"; + }); + + // Append the image to the floor + floor.appendChild(directionImage); + + // Add an element to the floor + for (let i = 0; i < elevators; i++) { + const floorImageDiv = document.createElement("div"); + floorImageDiv.className = "floorimages-div"; + floorImageDiv.id = i; + floorImages.appendChild(floorImageDiv); + } + + // Append the image to the floor + floor.appendChild(floorImages); + + //creating text container for floor name + const floorname = document.createElement("div"); + + // Add content to the floor, such as floor number + const floornumber = document.createElement("div"); + floornumber.className = "floor-number"; + floornumber.textContent = `Floor ${floorNumber}`; + // Append the floorname to the floor + floor.appendChild(floorname); + floor.appendChild(floornumber); + + //id + floor.id = `Floor ${floorNumber}`; + + floor.setAttribute("floorNumber", `${floorNumber}`); // Adding a custom attribute + // Append the floor to the building container + buildingContainer.appendChild(floor); +} +function generateLifts(elevators) { + const firstFloor = document.getElementById("Floor 1"); // Corrected ID + const floorImages = firstFloor.querySelector(".floor-images"); + + for (let i = 0; i < elevators; i++) { + // Target div for the lift image + const targetDiv = floorImages.querySelector(`:nth-child(${i + 1})`); + const left = targetDiv.offsetLeft; + const top = targetDiv.offsetTop; + + // Create a new image element for the elevator + // const liftImage = document.createElement("img"); + // liftImage.src = "/images/lift-image.jpg"; + // liftImage.className = "lift-image"; + // liftImage.setAttribute("floorDetail", `${1}`); // Adding a custom attribute + // liftImage.setAttribute("liftid", `${i+1}`); // Adding a custom attribute + // liftImage.id = `liftImage${i + 1}`; + // liftImage.style.position = "absolute"; + // liftImage.style.left = left + 65 + "px"; + // liftImage.style.top = top + 5 + "px"; + + // Create a new image element for the elevator + const liftImage = document.createElement("div"); + liftImage.classList.add("elevator"); + // liftImage.src = "/images/lift-image.jpg"; + liftImage.style.backgroundColor = "silver" + liftImage.style.overflow = "hidden"; + const leftDoor = document.createElement("div"); + leftDoor.id = "leftDoor"; + leftDoor.classList.add("door"); + leftDoor.style="background-color: blueviolet;" + const rightDoor = document.createElement("div"); + rightDoor.id = "rightDoor"; + rightDoor.classList.add("door"); + rightDoor.style="background-color: pink;" + liftImage.appendChild(leftDoor); + liftImage.appendChild(rightDoor); + liftImage.style.border = "5px solid blue"; + liftImage.className = "lift-image"; + liftImage.setAttribute("floorDetail", `${1}`); // Adding a custom attribute + liftImage.setAttribute("liftid", `${i+1}`); // Adding a custom attribute + liftImage.id = `liftImage${i + 1}`; + liftImage.style.position = "absolute"; + liftImage.style.left = left + 65 + "px"; + liftImage.style.top = top + 5 + "px"; + + // Append the elevator image to the floorImages container + building.appendChild(liftImage); + } +} + +document.addEventListener("DOMContentLoaded", function () { + // Generate a specific number of floors (e.g., 5 floors) with images + const numberOfFloors = floors; + for (let i = numberOfFloors; i >= 1; i--) { + const imageSource = `/images/lift-image.jpg`; // Replace with the actual image URL + divFloor = elevators - i - 1; + generateFloor(i, imageSource); + } + generateLifts(elevators); + // console.log("data store = ", dataStore); + // console.log("simulator"); +}); \ No newline at end of file diff --git a/js/main.js b/js/main.js new file mode 100644 index 00000000..cec4e6bf --- /dev/null +++ b/js/main.js @@ -0,0 +1,25 @@ +// console.log("hello") +document.addEventListener("DOMContentLoaded", function () { + // Get a reference to the form element + const elevatorForm = document.getElementById("elevatorForm"); + + elevatorForm.addEventListener("submit", function (e) { + e.preventDefault(); // Prevent the default form submission + + // Access the input values as integers + const floors = parseInt(document.getElementById("floors").value, 10); + const elevators = parseInt(document.getElementById("elevators").value, 10); + + // You now have the values as integers and can use them in your JavaScript code + console.log("Number of Floors: " + floors); + console.log("Number of Elevators Needed: " + elevators); + + // You can perform further actions or send this data to the server as needed + + // Construct the URL with query parameters + const url = `elevators.html?floors=${floors}&elevators=${elevators}`; + + // Redirect to the other page + window.location.href = url; + }); +}); diff --git a/src/css/main.css b/src/css/main.css deleted file mode 100644 index e69de29b..00000000 diff --git a/src/index.html b/src/index.html deleted file mode 100644 index e69de29b..00000000 diff --git a/src/js/main.js b/src/js/main.js deleted file mode 100644 index e69de29b..00000000 diff --git a/temp/1.html b/temp/1.html new file mode 100644 index 00000000..8d61ebca --- /dev/null +++ b/temp/1.html @@ -0,0 +1,16 @@ + + + + + + + Elevator Door Animation + + +
+
+
+
+ + + diff --git a/temp/script.js b/temp/script.js new file mode 100644 index 00000000..8a052655 --- /dev/null +++ b/temp/script.js @@ -0,0 +1,16 @@ +const leftDoor = document.getElementById('leftDoor'); +const rightDoor = document.getElementById('rightDoor'); + +function openDoors() { + leftDoor.style.transform = 'translateX(-100%)'; + rightDoor.style.transform = 'translateX(100%)'; +} + +function closeDoors() { + leftDoor.style.transform = 'translateX(0)'; + rightDoor.style.transform = 'translateX(0)'; +} + +// Example: Open the doors after 2 seconds and close them after 5 seconds +setTimeout(openDoors, 2000); +setTimeout(closeDoors, 5000); diff --git a/temp/temp.css b/temp/temp.css new file mode 100644 index 00000000..0f72b6d8 --- /dev/null +++ b/temp/temp.css @@ -0,0 +1,35 @@ +body { + display: flex; + align-items: center; + justify-content: center; + height: 100vh; + margin: 0; + background-color: #f0f0f0; +} + +.elevator { + position: relative; + width: 200px; /* Adjust the width as needed */ + height: 400px; + background-color: #333; + display: flex; + overflow: hidden; +} + +.door { + position: absolute; + width: 50%; + height: 100%; + background-color: #555; + transition: transform 0.5s ease-in-out; +} + +#leftDoor { + left: 0; + transform-origin: left; +} + +#rightDoor { + right: 0; + transform-origin: right; +}