Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pendulum Calculator #1801

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
30 changes: 30 additions & 0 deletions Calculators/Pendulum-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# <p align="center">Pendulum Calculator</p>

## Description :-

The Pendulum Calculator is a web application that calculates various properties of a pendulum system based on the length of the pendulum (l), the gravitational acceleration (g), the amplitude (A), and the mass of the bob (m). The calculator computes the following properties:

- Period of the Pendulum (T)
- Frequency of the Pendulum (f)
- Angular Frequency (ω)
- Maximum Speed
- Maximum Acceleration
- Kinetic Energy at the Lowest Point
- Potential Energy at the Highest Point

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Features :-

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

## Screenshots :-


29 changes: 29 additions & 0 deletions Calculators/Pendulum-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!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>Pendulum Calculator</title>
</head>
<body>
<header class="main">
<h1 class="header">Pendulum Calculator</h1>
<div class="calculator-container">
<label for="length">Length of Pendulum (l) in meters:</label>
<input type="number" id="length" name="length" required>
<label for="gravity">Gravitational Acceleration (g) in m/s²:</label>
<input type="number" id="gravity" name="gravity" required>
<label for="amplitude">Amplitude (A) in meters:</label>
<input type="number" id="amplitude" name="amplitude" required>
<label for="mass">Mass of the Bob (m) in kg:</label>
<input type="number" id="mass" name="mass" required>
<button class="submit-button" onclick="calculatePendulum()">Calculate</button>
<div class="results" id="results"></div>
</div>
</header>
<script src="script.js"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions Calculators/Pendulum-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function calculatePendulum() {
const length = parseFloat(document.getElementById('length').value);
const gravity = parseFloat(document.getElementById('gravity').value);
const amplitude = parseFloat(document.getElementById('amplitude').value);
const mass = parseFloat(document.getElementById('mass').value);

if (isNaN(length) || isNaN(gravity) || isNaN(amplitude) || isNaN(mass)) {
alert("Please enter valid numbers in all fields.");
return;
}

const T = 2 * Math.PI * Math.sqrt(length / gravity);
const f = 1 / T;
const w = 2 * Math.PI * f;
const v_max = amplitude * w;
const a_max = amplitude * Math.pow(w, 2);
const KE = 0.5 * mass * Math.pow(v_max, 2);
const PE = mass * gravity * amplitude;

const results = document.getElementById('results');
results.innerHTML = `
<h2>Results:</h2>
<p>Period of the Pendulum (T): ${T.toFixed(2)} s</p>
<p>Frequency of the Pendulum (f): ${f.toFixed(2)} Hz</p>
<p>Angular Frequency (ω): ${w.toFixed(2)} rad/s</p>
<p>Maximum Speed (v_max): ${v_max.toFixed(2)} m/s</p>
<p>Maximum Acceleration (a_max): ${a_max.toFixed(2)} m/s²</p>
<p>Kinetic Energy at the Lowest Point (KE): ${KE.toFixed(2)} J</p>
<p>Potential Energy at the Highest Point (PE): ${PE.toFixed(2)} J</p>
`;
}
Loading