Skip to content

Commit

Permalink
Added Beer Lambert Law Calculator (#1965)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaharwal authored Jan 3, 2025
1 parent c96d011 commit 2026b1e
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Calculators/Beer-Lambert-Law-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# <p align="center">Beer Lambert Law Calculator</p>

## Description :-

This project is a web-based calculator that implements the **Beer-Lambert Law**:

\[ A = \varepsilon \cdot c \cdot l \]

It allows users to calculate the absorbance (\( A \)) of a solution based on:

- \( \varepsilon \): Molar Absorptivity (L/mol·cm)
- \( c \): Concentration (mol/L)
- \( l \): Path Length (cm)

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Features :-

- **Dynamic Formula Display**: The formula is displayed in LaTeX for clarity.
- **Real-Time Results**: Automatically calculates the absorbance when valid inputs are provided.
- **Modern UI**: A responsive design with a stylish dark blue card background.
- **Error Handling**: Ensures all inputs are valid and provides feedback for invalid data.

## How to Use :-

1. Enter the values for:
- Molar Absorptivity (\( \varepsilon \)) in L/mol·cm
- Concentration (\( c \)) in mol/L
- Path Length (\( l \)) in cm.
2. Click the **Calculate** button to compute the absorbance (\( A \)).
3. Click the **Clear** button to reset the inputs and results.

### Example Calculation :-

#### Case:
- \( \varepsilon = 5000 \, \text{L/mol·cm} \)
- \( c = 0.02 \, \text{mol/L} \)
- \( l = 1 \, \text{cm} \)

#### Output:
- Absorbance (\( A \)):
\[
A = \varepsilon \cdot c \cdot l = 5000 \cdot 0.02 \cdot 1 = 100
\]

## Screenshots :-

![image](https://github.com/user-attachments/assets/9988db82-769e-4d6c-95f7-b2f0ed5b3b45)
Binary file not shown.
49 changes: 49 additions & 0 deletions Calculators/Beer-Lambert-Law-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!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">
<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>
<title>Beer Lambert Law Calculator</title>
</head>

<body>
<div class="calculator">
<h1>Beer-Lambert Law Calculator</h1>
<p class="formula">
Formula:
<span id="latex-formula">\( A = \varepsilon \cdot c \cdot l \)</span>
</p>

<p class="constant">Where:</p>

<ul>
<li>\( A \): Absorbance</li>
<li>\( \varepsilon \): Molar Absorptivity (L/mol·cm)</li>
<li>\( c \): Concentration (mol/L)</li>
<li>\( l \): Path Length (cm)</li>
</ul>

<label for="epsilon">Molar Absorptivity (\( \varepsilon \)):</label>
<input type="number" id="epsilon" placeholder="Enter Molar Absorptivity">

<label for="concentration">Concentration (\( c \)) (mol/L):</label>
<input type="number" id="concentration" placeholder="Enter Concentration">

<label for="length">Path Length (\( l \)) (cm):</label>
<input type="number" id="length" placeholder="Enter Path Length">

<div class="buttons">
<button onclick="calculateAbsorbance()">Calculate</button>
<button onclick="clearInputs()">Clear</button>
</div>
<div class="result" id="result"></div>
</div>

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

</html>
21 changes: 21 additions & 0 deletions Calculators/Beer-Lambert-Law-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function calculateAbsorbance() {
const epsilon = parseFloat(document.getElementById('epsilon').value);
const concentration = parseFloat(document.getElementById('concentration').value);
const length = parseFloat(document.getElementById('length').value);

if (isNaN(epsilon) || isNaN(concentration) || isNaN(length)) {
document.getElementById('result').innerText = "Please enter valid numbers for all fields.";
return;
}

const absorbance = epsilon * concentration * length;

document.getElementById('result').innerText = `Absorbance (A): ${absorbance.toFixed(2)}`;
}

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

.calculator {
background: #1565c0;
padding: 30px;
border-radius: 10px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
width: 450px;
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: 10px;
color: #bbdefb;
}

ul {
text-align: left;
margin: 10px 0 20px;
padding-left: 20px;
color: #bbdefb;
font-size: 14px;
}

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;
}
6 changes: 6 additions & 0 deletions calculators.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@
"link": "./Calculators/Bayes-Theorem-Calculator/index.html",
"source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Bayes-Theorem-Calculator"
},
{
"title": "Beer Lambert Law Calculator",
"description": "Calculates absorbance, concentration, or path length using the Beer-Lambert Law.",
"link": "./Calculators/Beer-Lambert-Law-Calculator/index.html",
"source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Beer-Lambert-Law-Calculator"
},
{
"title": "Beta Function Calculator",
"description": "Calculate the ß value of two numbers in a single click!",
Expand Down

0 comments on commit 2026b1e

Please sign in to comment.