Skip to content

Commit

Permalink
Added Capacitance Calculator (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
GAVINESHWAR authored Aug 8, 2024
1 parent 32e3480 commit b58521b
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Calculators/Capacitance-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Capacitance Calculator</p>

## Description :-

This calculator will help to find the capacitance in a parallel plate capacitor.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/user-attachments/assets/f9692a50-1dc2-4a22-89e8-33a2431b66a1)
35 changes: 35 additions & 0 deletions Calculators/Capacitance-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Capacitance Calculator</title>
</head>
<body>
<div class="calculator">
<h1>Parallel Plate Capacitor Calculator</h1>
<label for="area">A (plate area):</label>
<input type="number" id="area" placeholder="Enter area in mm²">
<span>(mm²)</span>
<br>
<label for="distance">d (distance):</label>
<input type="number" id="distance" placeholder="Enter distance in mm">
<span>(mm)</span>
<br>
<label for="dielectric">K (dielectric constant):</label>
<input type="number" id="dielectric" value="1">
<br>
<button onclick="computeCapacitance()">Compute</button>
<br>
<label for="capacitanceUF">Capacitance:</label>
<input type="text" id="capacitanceUF" readonly>
<span>(uF)</span>
<br>
<label for="capacitancePF">Capacitance:</label>
<input type="text" id="capacitancePF" readonly>
<span>(pF)</span>
</div>
<script src="script.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions Calculators/Capacitance-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function computeCapacitance() {
const epsilon0 = 8.854187817e-12; // Vacuum permittivity in F/m
const area = document.getElementById("area").value;
const distance = document.getElementById("distance").value;
const dielectric = document.getElementById("dielectric").value;

if (area && distance && dielectric) {
const areaMeters = area * 1e-6; // convert mm² to m²
const distanceMeters = distance * 1e-3; // convert mm to m
const capacitanceFarads =
(dielectric * epsilon0 * areaMeters) / distanceMeters;

const capacitanceMicroFarads = capacitanceFarads * 1e6;
const capacitancePicoFarads = capacitanceFarads * 1e12;

document.getElementById("capacitanceUF").value =
capacitanceMicroFarads.toFixed(6);
document.getElementById("capacitancePF").value =
capacitancePicoFarads.toFixed(6);
} else {
alert("Please fill in all fields.");
}
}
81 changes: 81 additions & 0 deletions Calculators/Capacitance-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
body {
font-family: Arial, sans-serif;
background: linear-gradient(to right, #4facfe, #00f2fe);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.calculator {
background: #ffffff;
padding: 20px;
border-radius: 15px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
text-align: center;
animation: fadeIn 1.5s ease-in-out;
}

h1 {
font-size: 1.5em;
margin-bottom: 20px;
color: #333;
}

label {
display: block;
margin: 10px 0 5px;
color: #555;
font-weight: bold;
}

input[type="number"],
input[type="text"] {
width: calc(100% - 30px);
padding: 10px;
margin-bottom: 10px;
border: 2px solid #ddd;
border-radius: 10px;
transition: border-color 0.3s;
}

input[type="number"]:focus,
input[type="text"]:focus {
border-color: #00f2fe;
outline: none;
}

button {
background: linear-gradient(to right, #ff416c, #ff4b2b);
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 25px;
cursor: pointer;
font-size: 1em;
transition: background 0.3s;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

button:hover {
background: linear-gradient(to right, #ff4b2b, #ff416c);
}

span {
color: #555;
font-weight: bold;
}

@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,20 @@ <h3>Calculates daily calorie intake based on given inputs.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Capacitance Calculator</h2>
<h3>Calculates the capacitance in a parallel plate capacitor.</h3>
<div class="card-footer">
<a href="./Calculators/Capacitance-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Capacitance-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>Capacitor Conversion Calculator</h2>
Expand Down

0 comments on commit b58521b

Please sign in to comment.