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

Added Coulombs Law Calculator #1964

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Changes from 1 commit
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
Next Next commit
Feat/Coloumb-Law-Calculator
dpgaharwal committed Dec 29, 2024

Verified

This commit was signed with the committer’s verified signature.
bonjourmauko Mauko Quiroga-Alvarado
commit 0d9d70f41ac61eaa670a4a302dcd232163d34194
Binary file not shown.
40 changes: 40 additions & 0 deletions Calculators/Coloumb-Law-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Coulomb's Law Calculator</title>
<link rel="stylesheet" href="style.css" />
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body>
<div class="calculator">
<h1>Coulomb's Law Calculator</h1>
<p class="formula">
Formula:
<span id="latex-formula">\( F = k \frac{q_1 \cdot q_2}{r^2} \)</span>
</p>
<p class="constant">
Where \( k = 8.987 \times 10^9 \, \text{N·m}^2/\text{C}^2 \)
</p>

<label for="q1">Charge 1 (\( q_1 \)) (C):</label>
<input type="number" id="q1" placeholder="Enter Charge 1" />

<label for="q2">Charge 2 (\( q_2 \)) (C):</label>
<input type="number" id="q2" placeholder="Enter Charge 2" />

<label for="r">Distance (\( r \)) (m):</label>
<input type="number" id="r" placeholder="Enter Distance" />

<div class="buttons">
<button onclick="calculateForce()">Calculate</button>
<button onclick="clearInputs()">Clear</button>
</div>

<div class="result" id="result"></div>
</div>
<script src="script.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions Calculators/Coloumb-Law-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function calculateForce() {
const q1 = parseFloat(document.getElementById('q1').value);
const q2 = parseFloat(document.getElementById('q2').value);
const r = parseFloat(document.getElementById('r').value);

if (isNaN(q1) || isNaN(q2) || isNaN(r) || r <= 0) {
document.getElementById('result').innerText = "Please enter valid numbers for all fields, and ensure distance is greater than zero.";
return;
}

const k = 8.9875517923e9; // Coulomb's constant in N·m²/C²
const force = (k * q1 * q2) / (r ** 2);

document.getElementById('result').innerText = `Force (F): ${force.toFixed(2)} N`;
}

function clearInputs() {
document.getElementById('q1').value = '';
document.getElementById('q2').value = '';
document.getElementById('r').value = '';
document.getElementById('result').innerText = '';
}
92 changes: 92 additions & 0 deletions Calculators/Coloumb-Law-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
body {
font-family: 'Roboto', sans-serif;
background-image: url('/Calculators/Coloumb-Law-Calculator/assest/col_background.webp');
background-size: cover;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: #fff;
}

.calculator {
background: #0d47a1; /* Dark blue background */
padding: 30px;
border-radius: 10px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
width: 400px;
text-align: center;
}

h1 {
font-size: 28px;
margin-bottom: 20px;
color: #ffeb3b;
}

.formula {
font-size: 16px;
margin-bottom: 10px;
color: #ffcc80;
}

.constant {
font-size: 14px;
margin-bottom: 20px;
color: #ffcc80;
}

label {
font-size: 14px;
margin: 10px 0 5px;
display: block;
text-align: left;
color: #bbdefb;
}

input {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 15px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
}

.buttons {
display: flex;
justify-content: space-between;
}

button {
background-color: #29b6f6;
color: white;
padding: 12px 20px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
margin: 5px;
flex: 1;
}

button:hover {
background-color: #0288d1;
}

button:last-child {
background-color: #f44336;
}

button:last-child:hover {
background-color: #d32f2f;
}

.result {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
color: #fff;
}