-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
442 lines (390 loc) · 14.7 KB
/
index.html
File metadata and controls
442 lines (390 loc) · 14.7 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Drake Equation Calculator</title>
<meta name="description" content="Interactive Drake Equation calculator built with pure HTML, CSS, and JavaScript." />
<style>
:root {
--bg: #0b1020;
--card: rgba(20, 28, 56, 0.9);
--text: #e6edf3;
--muted: #c2cee0;
--accent: #7cc4ff;
--accent-2: #9effa1;
--danger: #ff6b6b;
--shadow: 0 10px 30px rgba(0,0,0,0.45);
--radius: 14px;
}
* { box-sizing: border-box; }
html, body {
height: 100%;
margin: 0;
color: var(--text);
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
background: var(--bg) fixed no-repeat center/cover url('images/BG1.jpg');
}
.backdrop {
position: fixed;
inset: 0;
background: radial-gradient(1200px 800px at 70% -10%, rgba(124,196,255,0.20), transparent 60%),
radial-gradient(1000px 700px at -20% 120%, rgba(158,255,161,0.15), transparent 60%),
linear-gradient(180deg, rgba(7,10,20,0.78), rgba(7,10,20,0.78));
pointer-events: none;
}
.wrap {
min-height: 100%;
display: grid;
grid-template-rows: auto 1fr auto;
}
header {
padding: 32px 16px 0;
text-align: center;
}
header h1 {
margin: 0 0 8px;
font-weight: 800;
letter-spacing: 0.3px;
font-size: clamp(1.6rem, 3.5vw, 2.2rem);
}
header p {
margin: 0 auto;
max-width: 800px;
color: var(--muted);
font-size: 0.98rem;
line-height: 1.4rem;
}
.container {
padding: 24px 16px 48px;
display: grid;
place-items: center;
}
.card {
width: min(980px, 96vw);
background: var(--card);
border: 1px solid rgba(255,255,255,0.14);
box-shadow: var(--shadow);
border-radius: var(--radius);
overflow: hidden;
}
.grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 14px 16px;
padding: 22px;
}
.row {
grid-column: 1 / -1;
display: contents; /* use children placement */
}
.field {
grid-column: span 6;
background: rgba(255,255,255,0.06);
border: 1px solid rgba(255,255,255,0.12);
border-radius: 12px;
padding: 12px 12px 10px;
}
@media (max-width: 720px) {
.field { grid-column: 1 / -1; }
}
label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
font-weight: 600;
font-size: 0.96rem;
}
label .symbol {
color: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.hint {
margin-top: 4px;
color: var(--muted);
font-size: 0.86rem;
line-height: 1.2rem;
}
.inputs {
display: flex;
align-items: center;
gap: 10px;
margin-top: 10px;
}
input[type="number"] {
flex: 0 0 160px;
background: rgba(255,255,255,0.08);
color: var(--text);
border: 1px solid rgba(255,255,255,0.25);
border-radius: 10px;
padding: 8px 10px;
font-size: 1rem;
outline: none;
}
input[type="range"] {
flex: 1 1 auto;
}
.equation {
grid-column: 1 / -1;
margin: 2px 0 2px;
padding: 14px 12px;
background: rgba(255,255,255,0.06);
border: 1px dashed rgba(255,255,255,0.18);
border-radius: 12px;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
color: #e8f2ff;
overflow-x: auto;
white-space: nowrap;
}
.result {
grid-column: 1 / -1;
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 16px;
padding: 0 22px 22px;
}
.result .value {
font-size: clamp(1.6rem, 4vw, 2.4rem);
font-weight: 800;
letter-spacing: 0.3px;
}
.result .value small { color: var(--muted); font-weight: 600; }
.actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
button {
background: linear-gradient(180deg, rgba(124,196,255,0.45), rgba(124,196,255,0.25));
border: 1px solid rgba(124,196,255,0.8);
color: var(--text);
padding: 10px 14px;
border-radius: 10px;
cursor: pointer;
font-weight: 700;
}
button:hover { filter: brightness(1.06); }
footer {
text-align: center;
color: var(--muted);
padding: 12px 16px 28px;
font-size: 0.9rem;
}
a { color: var(--accent-2); text-decoration: none; }
</style>
</head>
<body>
<div class="wrap">
<header>
<h1>Drake Equation Calculator</h1>
<p>
Estimate the number of active, technologically advanced civilizations in our galaxy using the Drake equation.
Adjust the parameters below to see how your assumptions change the result.
</p>
</header>
<main class="container">
<section class="card" aria-labelledby="eq-title">
<div class="grid">
<div class="equation" id="eq-title" aria-live="polite">
N = R* × (1 - f_bin) × f_p × f_hz × n_e × (1 - f_gc) × f_t × f_l × f_i × f_c × L
</div>
<div class="row">
<div class="field">
<label for="rstar"><span class="symbol">R*</span> Average star formation rate (per year)
<input type="number" id="rstar" min="0" step="0.1" value="1.5" aria-describedby="hint-rstar" />
</label>
<p id="hint-rstar" class="hint">Average rate of star formation in the Milky Way.</p>
</div>
<div class="field">
<label for="fbin"><span class="symbol">f_bin</span> Fraction of new stars that are binary
<input type="number" id="fbin" min="0" max="1" step="0.01" value="0.55" aria-describedby="hint-fbin" />
</label>
<p id="hint-fbin" class="hint">Estimated fraction of newly formed stars that are binary (0–1). Higher values reduce N; the model uses (1 - f_bin) because close binaries can hinder stable, life-supporting planetary systems.</p>
</div>
<div class="field">
<label for="fp"><span class="symbol">f_p</span> Fraction of stars with planets
<input type="number" id="fp" min="0" max="1" step="0.01" value="0.9" aria-describedby="hint-fp" />
</label>
<p id="hint-fp" class="hint">Proportion of stars that have planetary systems (0–1).</p>
</div>
<div class="field">
<label for="fhz"><span class="symbol">f_hz</span> Fraction in habitable zones
<input type="number" id="fhz" min="0" max="1" step="0.01" value="0.25" aria-describedby="hint-fhz" />
</label>
<p id="hint-fhz" class="hint">Proportion of planets located within their star’s habitable zone (0–1).</p>
</div>
<div class="field">
<label for="ne"><span class="symbol">n_e</span> Habitable planets per system
<input type="number" id="ne" min="0" step="0.01" value="0.5" aria-describedby="hint-ne" />
</label>
<p id="hint-ne" class="hint">Average number of potentially habitable planets per stars habitable zone.</p>
</div>
<div class="field">
<label for="fgc"><span class="symbol">f_gc</span> Fraction near galactic core
<input type="number" id="fgc" min="0" max="1" step="0.01" value="0.2" aria-describedby="hint-fgc" />
</label>
<p id="hint-fgc" class="hint">Proportion of stellar systems close to the galactic core (0–1). Higher values reduce N; because proximity to the core is detrimental.</p>
</div>
<div class="field">
<label for="ft"><span class="symbol">f_t</span> Fraction with plate tectonics
<input type="number" id="ft" min="0" max="1" step="0.01" value="0.6" aria-describedby="hint-ft" />
</label>
<p id="hint-ft" class="hint">Proportion of habitable planets that have active plate tectonics (0–1).</p>
</div>
<div class="field">
<label for="fl"><span class="symbol">f_l</span> Fraction where life appears
<input type="number" id="fl" min="0" max="1" step="0.01" value="0.33" aria-describedby="hint-fl" />
</label>
<p id="hint-fl" class="hint">Proportion of habitable planets where life actually emerges (0–1).</p>
</div>
<div class="field">
<label for="fi"><span class="symbol">f_i</span> Fraction with intelligent life
<input type="number" id="fi" min="0" max="1" step="0.001" value="0.05" aria-describedby="hint-fi" />
</label>
<p id="hint-fi" class="hint">Proportion of life-bearing planets that develop intelligent life (0–1).</p>
</div>
<div class="field">
<label for="fc"><span class="symbol">f_c</span> Fraction that communicate
<input type="number" id="fc" min="0" max="1" step="0.01" value="0.1" aria-describedby="hint-fc" />
</label>
<p id="hint-fc" class="hint">Proportion that develop detectable communications (0–1).</p>
</div>
<div class="field" style="grid-column: span 12;">
<label for="L"><span class="symbol">L</span> Communicating lifetime (years)
<input type="number" id="L" min="0" step="1" value="10000" aria-describedby="hint-L" />
</label>
<p id="hint-L" class="hint">Average length of time civilizations release detectable signals.</p>
</div>
</div>
</div>
<div class="result">
<div class="value" id="resultValue" aria-live="polite">
N ≈ 0
</div>
<div class="actions">
<button id="resetBtn" type="button" title="Reset to defaults">Reset</button>
<button id="copyBtn" type="button" title="Copy current values as a shareable link">Copy Link</button>
</div>
</div>
</section>
</main>
<footer>
Built with pure HTML, CSS, and JavaScript. Background image courtesy of the repository.
</footer>
</div>
<script>
(function() {
const $ = (id) => document.getElementById(id);
const fields = ['rstar','fbin','fp','fhz','ne','fgc','ft','fl','fi','fc','L'];
function clamp(value, min, max) {
if (Number.isNaN(value)) return 0;
if (typeof min === 'number' && value < min) return min;
if (typeof max === 'number' && value > max) return max;
return value;
}
function parseVal(id) {
const el = $(id);
const raw = parseFloat(el.value);
switch(id) {
case 'rstar': return clamp(raw, 0, undefined);
case 'L': return clamp(raw, 0, undefined);
case 'fp':
case 'fl':
case 'fi':
case 'fc':
case 'ft':
case 'fhz':
case 'fgc':
case 'fbin':
return clamp(raw, 0, 1);
case 'ne': return clamp(raw, 0, undefined);
default: return 0;
}
}
function fmtNumber(n) {
if (!isFinite(n)) return '0';
if (n === 0) return '0';
if (n < 0.001) return n.toExponential(2);
if (n < 1e3) return n.toLocaleString(undefined, { maximumFractionDigits: 6 });
if (n < 1e6) return n.toLocaleString(undefined, { maximumFractionDigits: 2 });
return n.toExponential(2);
}
function updateEquationText() {
const eq = `N = ${parseVal('rstar')} × ${(1 - parseVal('fbin')).toFixed(2)} × ${parseVal('fp')} × ${parseVal('fhz')} × ${parseVal('ne')} × ${(1 - parseVal('fgc')).toFixed(2)} × ${parseVal('ft')} × ${parseVal('fl')} × ${parseVal('fi')} × ${parseVal('fc')} × ${parseVal('L')}`;
document.querySelector('.equation').textContent = eq;
}
function compute() {
const rstar = parseVal('rstar');
const fbin_effect = 1 - parseVal('fbin');
const fp = parseVal('fp');
const fhz = parseVal('fhz');
const ne = parseVal('ne');
const fgc_effect = 1 - parseVal('fgc');
const ft = parseVal('ft');
const fl = parseVal('fl');
const fi = parseVal('fi');
const fc = parseVal('fc');
const L = parseVal('L');
const N = rstar * fbin_effect * fp * fhz * ne * fgc_effect * ft * fl * fi * fc * L;
const res = document.getElementById('resultValue');
res.innerHTML = `N ≈ ${fmtNumber(N)} <small>civilizations</small>`;
updateEquationText();
}
function setDefaults() {
$('rstar').value = 1.5;
$('fbin').value = 0.55;
$('fp').value = 0.9;
$('ne').value = 0.2;
$('fl').value = 0.5;
$('fi').value = 0.05;
$('fc').value = 0.3;
$('ft').value = 0.6;
$('fhz').value = 0.25;
$('fgc').value = 0.2;
$('L').value = 10000;
}
function loadFromQuery() {
const q = new URLSearchParams(location.search);
let changed = false;
for (const id of fields) {
if (q.has(id)) {
const v = parseFloat(q.get(id));
if (!Number.isNaN(v)) { $(id).value = v; changed = true; }
}
}
return changed;
}
function copyLink() {
const q = new URLSearchParams();
for (const id of fields) q.set(id, $(id).value);
const url = `${location.origin}${location.pathname}?${q.toString()}`;
navigator.clipboard.writeText(url).then(() => {
const btn = document.getElementById('copyBtn');
const prev = btn.textContent;
btn.textContent = 'Copied!';
setTimeout(() => (btn.textContent = prev), 1200);
}).catch(() => {
alert('Copy failed. You can manually copy the URL from the address bar.');
});
}
// Wire up events
for (const id of fields) {
$(id).addEventListener('input', compute);
$(id).addEventListener('change', compute);
}
document.getElementById('resetBtn').addEventListener('click', () => {
setDefaults();
compute();
history.replaceState(null, '', location.pathname);
});
document.getElementById('copyBtn').addEventListener('click', copyLink);
// Initialize
setDefaults();
if (loadFromQuery()) compute();
compute();
})();
</script>
</body>
</html>