Skip to content

Commit

Permalink
Added Mass Spring Calculator (#1800)
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryByte authored Aug 10, 2024
1 parent 01d725c commit 8bb7f02
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Calculators/Mass-Spring-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# <p align="center">Mass-Spring Calculator</p>

## Description :-

The Mass-Spring Calculator is a web application that calculates various properties of a mass-spring system. Given the mass of the object (m), the spring constant (k), and the amplitude (A), the calculator computes the following properties:

- Period of Oscillation (T)
- Frequency of Oscillation (f)
- Angular Frequency (ω)
- Maximum Speed (v_max)
- Maximum Acceleration (a_max)
- Kinetic Energy at Maximum Speed (KE)
- Potential Energy at Maximum Displacement (PE)

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Features :-

- Calculate the period, frequency, angular frequency, maximum speed, maximum acceleration, kinetic energy, and potential energy of a mass-spring system.
- User-friendly interface with input fields for mass, spring constant, and amplitude.
- Responsive design with a background image and enhanced styling.
- Clear and detailed display of calculated results.



44 changes: 44 additions & 0 deletions Calculators/Mass-Spring-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap" rel="stylesheet">
<title>Mass-Spring Calculator</title>
</head>

<body>
<header class="main">
<h1 class="header">Mass-Spring Calculator</h1>
<div class="calculator-container">
<label for="mass">Mass (m): </label>
<input type="number" id="mass" name="mass" step="0.01" required>

<label for="spring-constant">Spring Constant (k): </label>
<input type="number" id="spring-constant" name="spring-constant" step="0.01" required>

<label for="amplitude">Amplitude (A): </label>
<input type="number" id="amplitude" name="amplitude" step="0.01" required>

<button class="submit-button" onclick="calculateProperties()">Calculate</button>

<div id="results" class="results">
<h2>Results:</h2>
<p id="period"></p>
<p id="frequency"></p>
<p id="angular-frequency"></p>
<p id="max-speed"></p>
<p id="max-acceleration"></p>
<p id="kinetic-energy"></p>
<p id="potential-energy"></p>
</div>
</div>
</header>

<script src="script.js"></script>
</body>

</html>
40 changes: 40 additions & 0 deletions Calculators/Mass-Spring-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function calculateProperties() {
const mass = parseFloat(document.getElementById('mass').value);
const springConstant = parseFloat(document.getElementById('spring-constant').value);
const amplitude = parseFloat(document.getElementById('amplitude').value);

if (isNaN(mass) || isNaN(springConstant) || isNaN(amplitude)) {
alert("Please enter valid numbers for mass, spring constant, and amplitude.");
return;
}

// Period of Oscillation (T)
const period = 2 * Math.PI * Math.sqrt(mass / springConstant);

// Frequency of Oscillation (f)
const frequency = 1 / period;

// Angular Frequency (ω)
const angularFrequency = 2 * Math.PI * frequency;

// Maximum Speed (v_max)
const maxSpeed = angularFrequency * amplitude;

// Maximum Acceleration (a_max)
const maxAcceleration = angularFrequency * angularFrequency * amplitude;

// Kinetic Energy at Maximum Speed (KE)
const kineticEnergy = 0.5 * mass * maxSpeed * maxSpeed;

// Potential Energy at Maximum Displacement (PE)
const potentialEnergy = 0.5 * springConstant * amplitude * amplitude;

// Display results
document.getElementById('period').textContent = `Period of Oscillation (T): ${period.toFixed(2)} s`;
document.getElementById('frequency').textContent = `Frequency of Oscillation (f): ${frequency.toFixed(2)} Hz`;
document.getElementById('angular-frequency').textContent = `Angular Frequency (ω): ${angularFrequency.toFixed(2)} rad/s`;
document.getElementById('max-speed').textContent = `Maximum Speed (v_max): ${maxSpeed.toFixed(2)} m/s`;
document.getElementById('max-acceleration').textContent = `Maximum Acceleration (a_max): ${maxAcceleration.toFixed(2)} m/s²`;
document.getElementById('kinetic-energy').textContent = `Kinetic Energy (KE): ${kineticEnergy.toFixed(2)} J`;
document.getElementById('potential-energy').textContent = `Potential Energy (PE): ${potentialEnergy.toFixed(2)} J`;
}
116 changes: 116 additions & 0 deletions Calculators/Mass-Spring-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
body {
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: linear-gradient(to right, #1e3c72, #2a5298);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
flex-direction: column;
min-height: 100vh;
}

.header {
font-size: 3em;
font-weight: bold;
background: linear-gradient(to right, #ff6b6b, #ff9f43);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
animation: fadeInScale 2s ease-in-out;
margin-bottom: 20px;
}

@keyframes fadeInScale {
0% {
opacity: 0;
transform: scale(0.8);
}
100% {
opacity: 1;
transform: scale(1);
}
}

.main {
text-align: center;
background: rgba(255, 255, 255, 0.95);
padding: 30px;
border-radius: 15px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
max-width: 400px;
width: 100%;
}

.calculator-container {
background-color: rgba(255, 255, 255, 0.9);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
border-radius: 10px;
padding: 20px;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

label {
font-size: 1.2em;
color: #333;
margin-bottom: 10px;
}

input {
padding: 10px;
font-size: 1em;
border: 1px solid #ddd;
border-radius: 4px;
background-color: #f9f9f9;
margin-bottom: 15px;
width: 100%;
box-sizing: border-box;
}

input:focus {
border-color: #007bff;
outline: none;
}

.submit-button {
display: inline-block;
padding: 12px 24px;
background-color: #5d13d4;
color: white;
border: none;
border-radius: 25px;
cursor: pointer;
font-size: 1em;
transition: background-color 0.3s, transform 0.3s;
}

.submit-button:hover {
background-color: #45a049;
transform: scale(1.05);
}

.results {
margin-top: 20px;
text-align: left;
width: 100%;
}

.results h2 {
margin-bottom: 10px;
font-size: 1.5em;
color: #333;
}

.results p {
margin: 8px 0;
font-size: 1em;
color: #555;
}
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ <h3>Calculate the theoretical resistance of a 5-band resistor.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Mass-Spring Calculator</h2>
<h3>Calculates various properties of a mass-spring system.</h3>
<div class="card-footer">
<a href="./Calculators/Mass-Spring-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Mass-Spring-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>

<div class="box">
<div class="content">
<h2>6 Band Resistance Calculator</h2>
Expand Down

0 comments on commit 8bb7f02

Please sign in to comment.