-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Falling Object Calculator (#1846)
- Loading branch information
1 parent
2412a43
commit 160d174
Showing
5 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# <p align="center">Falling Object Under Gravity Calculator</p> | ||
|
||
## Description :- | ||
|
||
This calculator estimates the time and speed of a free-falling object under gravity (9.81 m/s²), neglecting air resistance. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots :- | ||
|
||
|
||
![Screenshot 2024-08-10 180118](https://github.com/user-attachments/assets/8ad73eb9-36dc-44f0-abd1-61d974a7d382) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Falling Object Under Gravity Calculator</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Falling Object Calculator</h1> | ||
<div class="input-group"> | ||
<label for="height">Height (meters):</label> | ||
<input type="number" id="height" min="0" step="0.01" placeholder="Enter height in meters"> | ||
</div> | ||
<button onclick="calculate()">Calculate</button> | ||
<div id="result"></div> | ||
<div class="explanation"> | ||
This calculator estimates the time and speed of a free-falling object under gravity (9.81 m/s²), neglecting air resistance. | ||
</div> | ||
<div class="animation-container"> | ||
<div class="animation-circle"></div> | ||
</div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function calculate() { | ||
const g = 9.81; // Acceleration due to gravity (m/s^2) | ||
const heightInput = document.getElementById('height'); | ||
const resultDiv = document.getElementById('result'); | ||
|
||
const height = parseFloat(heightInput.value); | ||
|
||
if (isNaN(height) || height < 0) { | ||
resultDiv.innerHTML = 'Please enter a valid height.'; | ||
resultDiv.style.color = '#dc3545'; // Change color to red for error | ||
return; | ||
} | ||
|
||
const time = Math.sqrt((2 * height) / g); | ||
const speed = g * time; | ||
|
||
resultDiv.style.color = '#28a745'; // Change color to green for valid result | ||
resultDiv.innerHTML = ` | ||
<p>Time to fall: ${time.toFixed(2)} seconds</p> | ||
<p>Speed: ${speed.toFixed(2)} m/s</p> | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
body { | ||
font-family: 'Arial', sans-serif; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 100vh; | ||
background: linear-gradient(to right, #6b11cbb6, #fc2594); | ||
color: #333; | ||
overflow: auto; | ||
} | ||
|
||
.container { | ||
background-color: #ffffff41; | ||
padding: 60px 80px; | ||
border-radius: 20px; | ||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3); | ||
text-align: center; | ||
width: 600px; | ||
max-width: 90%; | ||
position: relative; | ||
overflow: auto; | ||
} | ||
|
||
h1 { | ||
color: #333; | ||
margin-bottom: 30px; | ||
font-size: 3em; | ||
text-shadow: 0 3px 6px rgba(0, 0, 0, 0.2); | ||
text-align: center; | ||
font-weight: bold; | ||
letter-spacing: 2px; | ||
} | ||
|
||
.input-group { | ||
display: flex; | ||
flex-direction: column; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.input-group label { | ||
margin-bottom: 5px; | ||
font-weight: bold; | ||
font-size: 1.2em; | ||
} | ||
|
||
input[type="number"] { | ||
width: calc(100% - 22px); | ||
padding: 15px; | ||
margin: 10px 0; | ||
border: 1px solid #ccc; | ||
border-radius: 8px; | ||
box-sizing: border-box; | ||
font-size: 18px; | ||
transition: border-color 0.3s ease; | ||
} | ||
|
||
input[type="number"]:focus { | ||
outline: none; | ||
border-color: #007bff; | ||
box-shadow: 0 0 5px #007bff; | ||
} | ||
|
||
button { | ||
background-color: #007bff; | ||
color: white; | ||
padding: 15px 30px; | ||
border: none; | ||
border-radius: 8px; | ||
cursor: pointer; | ||
font-size: 18px; | ||
font-weight: bold; | ||
transition: background-color 0.3s ease, transform 0.1s ease; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
button:hover { | ||
background-color: #0056b3; | ||
transform: translateY(-3px); | ||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2); | ||
} | ||
|
||
#result { | ||
margin-top: 40px; | ||
font-size: 2.2em; | ||
font-weight: bold; | ||
color: #28a745; | ||
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | ||
animation: blink 1.2s infinite; | ||
} | ||
|
||
@keyframes blink { | ||
0% { opacity: 1; } | ||
50% { opacity: 0.7; } | ||
100% { opacity: 1; } | ||
} | ||
|
||
.explanation { | ||
margin-top: 30px; | ||
font-size: 1.1em; | ||
color: #df4941; | ||
line-height: 1.6; | ||
} | ||
|
||
.animation-container { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
width: 100%; | ||
height: 100%; | ||
pointer-events: none; | ||
z-index: -1; | ||
} | ||
|
||
.animation-circle { | ||
position: absolute; | ||
width: 150px; | ||
height: 150px; | ||
border-radius: 50%; | ||
background-color: rgba(255, 255, 255, 0.2); | ||
animation: circleAnimation 7s linear infinite; | ||
} | ||
|
||
@keyframes circleAnimation { | ||
0% { | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
opacity: 1; | ||
} | ||
100% { | ||
top: 10%; | ||
left: 90%; | ||
transform: translate(-50%, -50%) scale(2.5); | ||
opacity: 0.05; | ||
} | ||
} | ||
|
||
/* Responsive Design (adjust for different screen sizes) */ | ||
@media (max-width: 600px) { | ||
.container { | ||
width: 90%; | ||
padding: 40px 20px; | ||
} | ||
h1 { | ||
font-size: 2.2em; | ||
} | ||
.animation-circle { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters