-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
78 lines (72 loc) · 2.69 KB
/
Copy pathmain.html
File metadata and controls
78 lines (72 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Electron Configuration Calculator</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
.fade-enter {
opacity: 0;
transform: translateY(10px);
}
.fade-enter-active {
opacity: 1;
transform: translateY(0);
transition: opacity 0.3s, transform 0.3s;
}
</style>
</head>
<body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
<div class="w-full max-w-2xl">
<h1 class="text-4xl font-bold text-center mb-6 text-white">Electron Configuration Calculator</h1>
<div class="bg-gray-800 rounded-2xl p-6 shadow-xl">
<label for="electronInput" class="block mb-2 text-lg font-medium">Enter number of electrons:</label>
<input id="electronInput" type="number" min="1" max="9999" value="118" class="w-full p-3 rounded-xl bg-gray-700 text-white focus:outline-none focus:ring-2 focus:ring-blue-500 transition" />
</div>
<div id="output" class="mt-6 space-y-2 text-lg leading-relaxed"></div>
</div>
<script>
const labels = ['s','p','d','f','g','h','i','j','k','l','m','n','o','q','r','t'];
function generateOrbitals(limit = 20) {
const orbitals = [];
for (let n = 1; n <= limit; n++) {
for (let l = 0; l < Math.min(n, labels.length); l++) {
const label = labels[l];
const capacity = 2 * (2 * l + 1);
orbitals.push({ n, l, label, capacity, energy: n + l });
}
}
return orbitals.sort((a, b) => a.energy - b.energy || a.n - b.n);
}
function buildConfig(electrons) {
const orbitals = generateOrbitals(30);
const config = [];
for (const orb of orbitals) {
if (electrons <= 0) break;
const fill = Math.min(orb.capacity, electrons);
config.push(`${orb.n}${orb.label}<sup>${fill}</sup>`);
electrons -= fill;
}
return config.join(' ');
}
const input = document.getElementById('electronInput');
const output = document.getElementById('output');
function updateOutput() {
const e = parseInt(input.value);
if (isNaN(e) || e < 1) {
output.innerHTML = '<p class="text-red-400">Please enter a valid positive number.</p>';
return;
}
const result = buildConfig(e);
output.innerHTML = `
<div class="fade-enter-active p-4 bg-gray-800 rounded-2xl shadow-md">
<span class="text-blue-400 font-mono">${result}</span>
</div>
`;
}
input.addEventListener('input', updateOutput);
window.addEventListener('load', updateOutput);
</script>
</body>
</html>