-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Beer Lambert Law Calculator (#1965)
- Loading branch information
1 parent
c96d011
commit 2026b1e
Showing
6 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters