-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.html
More file actions
615 lines (558 loc) · 17.2 KB
/
clock.html
File metadata and controls
615 lines (558 loc) · 17.2 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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Solar System Orbital Trajectories Animation</title>
<link rel="manifest" href="manifest.json">
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
background-color: #000;
color: #fff;
font-family: monospace;
overflow-y: auto;
min-height: 100%;
display: flex;
flex-direction: column;
}
#canvas-wrapper {
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
position: relative;
margin: 5px 0;
}
.footer-logo-container {
text-align: center;
width: 100%;
padding: 10px 0 0 0;
margin-top: 0;
}
h1 {
margin: 15px;
font-size: 1.2rem;
text-align: center;
}
.logo-image {
display: inline-block;
opacity: 1;
max-width: 48px;
transition: opacity 0.3s, transform 0.3s;
vertical-align: middle;
}
.logo-image:hover {
opacity: 0.8;
transform: scale(1.1);
}
#controls {
display: flex;
font-family: monospace;
justify-content: center;
gap: 15px;
padding-bottom: 5px;
flex-wrap: wrap;
margin-bottom: 5px;
}
#controls label {
display: flex;
align-items: center;
gap: 5px;
font-size: 0.9rem;
}
#orbitCanvas {
background-color: #000;
display: block;
max-width: 100%;
max-height: 100%;
touch-action: auto;
}
#legend {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
margin-top: 5px;
margin-bottom: 20px;
font-size: 0.8rem;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
cursor: pointer;
}
.color-box {
width: 12px;
height: 12px;
border-radius: 50%;
position: relative;
}
.color-box input {
position: absolute;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
#info {
text-align: center;
font-size: 0.8rem;
margin: 0px;
padding: 0 10px;
}
.help-link {
position: center;
text-align: center;
margin: 5px;
top: 70px;
color: #777;
font-size: 18px;
text-decoration: none;
font-family: monospace;
}
.hidden-planet {
opacity: 0.3;
}
.speed-control {
width: 100%;
padding: 0 0px;
margin-top: 5px;
text-align: center;
}
.speed-control label {
display: block;
margin-bottom: 5px;
}
.speed-slider {
width: 80%;
margin-bottom: 0px;
}
#pause-btn {
margin-bottom: 5px;
padding: 5px 10px;
background: #333;
color: white;
border: none;
border-radius: 0px;
cursor: pointer;
}
#date-picker {
margin: 5px 5px;
background: #333;
color: white;
border: none;
padding: 5px;
font-family: monospace;
}
.control-container {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
margin-bottom: 5px;
}
footer {
margin-top: auto;
padding: 20px 0;
display: flex;
justify-content: center;
}
.donate-box {
display: flex;
flex-direction: column;
align-items: center; /* Центрування вмісту */
gap: 10px;
}
.donate-btn {
color: #fff;
border: 1px solid #fff;
padding: 5px 15px;
background: transparent;
cursor: pointer;
font-family: monospace;
width: fit-content;
transition: 0.3s;
}
.donate-btn:hover {
background: #aaa;
color: #000;
}
.crypto-info {
display: none;
flex-direction: column;
align-items: center; /* Центрування тексту та адреси */
gap: 5px;
margin-top: 10px;
}
.crypto-address-display {
font-size: 10px;
color: #fff;
background: #111;
padding: 8px 12px;
border: 1px dashed #fff;
cursor: copy;
word-break: break-all;
max-width: 280px;
text-align: center;
}
</style>
</head>
<body>
<script src="pwa-init.js"></script>
<div class="footer-logo-container">
<a href="index.html">
<img src="logo.png" alt="Logo" class="logo-image">
</a>
</div>
<h1>Solar System Model</h1>
<div class="speed-control">
<div class="control-container">
<label for="date-picker">Date:</label>
<input type="date" id="date-picker" value="2000-01-01">
<button id="pause-btn">Pause</button>
</div>
<input type="range" id="speed-slider" class="speed-slider" min="0.1" max="1" step="0.1" value="0.3">
</div>
<div id="canvas-wrapper">
<canvas id="orbitCanvas"></canvas>
</div>
<div id="controls">
<label><input type="radio" name="frame" value="sun" checked> Sun</label>
<label><input type="radio" name="frame" value="earth"> Earth</label>
</div>
<div id="legend"></div>
<div id="info"></div>
<script>
const canvas = document.getElementById('orbitCanvas');
const ctx = canvas.getContext('2d');
const legendDiv = document.getElementById('legend');
function initCanvas() {
const wrapper = document.getElementById('canvas-wrapper');
const size = Math.min(window.innerWidth, window.innerHeight * 0.6);
canvas.width = size;
canvas.height = size;
canvas.style.width = `${size}px`;
canvas.style.height = `${size}px`;
}
window.addEventListener('resize', () => {
initCanvas();
trajectories.forEach(arr => arr.length = 0);
});
const planets = [
{name: 'Mercury', distance: 0.387, period: 88, color: '#1e90ff', eccentricity: 0.2056, inclination: 0.1222},
{name: 'Venus', distance: 0.723, period: 225, color: '#8F00FF', eccentricity: 0.0068, inclination: 0.0593},
{name: 'Earth', distance: 1.000, period: 365.25, color: '#008000', eccentricity: 0.0167, inclination: 0},
{name: 'Mars', distance: 1.524, period: 687, color: '#ff4500', eccentricity: 0.0934, inclination: 0.0323},
{name: 'Jupiter', distance: 5.203, period: 4333, color: '#daa520', eccentricity: 0.0489, inclination: 0.0228},
{name: 'Saturn', distance: 9.537, period: 10759, color: '#deb887', eccentricity: 0.0565, inclination: 0.0436},
{name: 'Uranus', distance: 19.191, period: 30687, color: '#40e0d0', eccentricity: 0.0464, inclination: 0.0135},
{name: 'Neptune', distance: 30.068, period: 60190, color: '#4169e1', eccentricity: 0.0095, inclination: 0.0309}
];
let planetVisibility = planets.map(() => true);
function createLegend() {
legendDiv.innerHTML = '';
planets.forEach((planet, index) => {
const item = document.createElement('div');
item.className = 'legend-item';
const colorBox = document.createElement('div');
colorBox.className = 'color-box';
colorBox.style.backgroundColor = planet.color
if (!planetVisibility[index]) {
colorBox.classList.add('hidden-planet');
}
const label = document.createElement('span');
label.textContent = planet.name;
if (!planetVisibility[index]) {
label.classList.add('hidden-planet');
}
item.append(colorBox, label);
legendDiv.appendChild(item);
item.addEventListener('click', () => {
planetVisibility[index] = !planetVisibility[index];
if (planetVisibility[index]) {
colorBox.classList.remove('hidden-planet');
label.classList.remove('hidden-planet');
} else {
colorBox.classList.add('hidden-planet');
label.classList.add('hidden-planet');
}
if (planet.name === 'Earth' && !planetVisibility[index] && frame === 'earth') {
document.querySelector('input[name="frame"][value="sun"]').checked = true;
frame = 'sun';
}
trajectories.forEach(arr => arr.length = 0);
});
});
}
initCanvas();
createLegend();
const maxDistance = planets[planets.length - 1].distance;
const margin = 40;
let maxOrbitRadius;
function orbitRadius(ae) {
return (ae / maxDistance) * maxOrbitRadius;
}
const J2000 = new Date('2000-01-01T12:00:00Z');
let t = 0;
let dt = 0.3;
let frame = 'sun';
const earthIndex = planets.findIndex(p => p.name === 'Earth');
const trajectories = planets.map(() => []);
let scale = 10;
let offsetX = 0;
let offsetY = 0;
document.getElementById('controls').addEventListener('change', (e) => {
if (e.target.name === 'frame') {
frame = e.target.value;
if (frame === 'earth') {
const earthIdx = planets.findIndex(p => p.name === 'Earth');
if (!planetVisibility[earthIdx]) {
planetVisibility[earthIdx] = true;
createLegend();
}
}
trajectories.forEach(arr => arr.length = 0);
offsetX = 0;
offsetY = 0;
scale = 10;
}
});
const speedSlider = document.getElementById('speed-slider');
speedSlider.addEventListener('input', (e) => {
dt = parseFloat(e.target.value);
});
const datePicker = document.getElementById('date-picker');
datePicker.addEventListener('change', (e) => {
const selectedDate = new Date(e.target.value + 'T12:00:00Z');
const msInDay = 86400000;
t = (selectedDate.getTime() - J2000.getTime()) / msInDay;
isPaused = true;
pauseBtn.textContent = 'Resume';
});
let isPaused = false;
const pauseBtn = document.getElementById('pause-btn');
pauseBtn.addEventListener('click', () => {
isPaused = !isPaused;
pauseBtn.textContent = isPaused ? 'Resume' : 'Pause';
if (!isPaused) {
animate();
}
});
canvas.addEventListener('wheel', e => {
e.preventDefault();
const zoomSpeed = 0.001;
const prevScale = scale;
scale += e.deltaY * -zoomSpeed * scale;
scale = Math.max(0.1, Math.min(scale, 50));
const scaleChange = scale / prevScale;
offsetX = offsetX * scaleChange;
offsetY = offsetY * scaleChange;
trajectories.forEach(arr => arr.length = 0);
}, {passive: false});
let isDragging = false;
let lastX, lastY;
canvas.addEventListener('mousedown', e => {
if (e.button === 0) {
isDragging = true;
lastX = e.clientX;
lastY = e.clientY;
}
});
window.addEventListener('mousemove', e => {
if (!isDragging) return;
const dx = e.clientX - lastX;
const dy = e.clientY - lastY;
offsetX += dx;
offsetY += dy;
lastX = e.clientX;
lastY = e.clientY;
trajectories.forEach(arr => arr.length = 0);
});
window.addEventListener('mouseup', () => {
isDragging = false;
});
let lastTouchDistance = null;
canvas.addEventListener('touchmove', function (e) {
if (e.touches.length === 2) {
e.preventDefault();
const dx = e.touches[0].clientX - e.touches[1].clientX;
const dy = e.touches[0].clientY - e.touches[1].clientY;
const distance = Math.sqrt(dx * dx + dy * dy);
if (lastTouchDistance !== null) {
const zoomIntensity = 0.001;
const delta = distance - lastTouchDistance;
const prevScale = scale;
scale *= (1 + zoomIntensity * delta);
scale = Math.max(0.1, Math.min(scale, 50));
const scaleChange = scale / prevScale;
offsetX = offsetX * scaleChange;
offsetY = offsetY * scaleChange;
trajectories.forEach(arr => arr.length = 0);
}
lastTouchDistance = distance;
}
}, { passive: false });
canvas.addEventListener('touchend', () => {
lastTouchDistance = null;
});
function drawPoint(x, y, color, size = 4) {
ctx.beginPath();
ctx.fillStyle = color;
ctx.shadowColor = color;
ctx.shadowBlur = 8;
ctx.arc(x, y, size, 0, Math.PI * 2);
ctx.fill();
ctx.shadowBlur = 0;
}
function getCurrentDate() {
const msInDay = 86400000;
const currentDate = new Date(J2000.getTime() + t * msInDay);
return currentDate.toISOString().split('T')[0];
}
function solveKepler(M, e, tolerance = 1e-6) {
let E = M;
let delta;
do {
delta = (E - e * Math.sin(E) - M) / (1 - e * Math.cos(E));
E -= delta;
} while (Math.abs(delta) > tolerance);
return E;
}
function getTrueAnomaly(E, e) {
const cosTheta = (Math.cos(E) - e) / (1 - e * Math.cos(E));
const sinTheta = Math.sqrt(1 - e * e) * Math.sin(E) / (1 - e * Math.cos(E));
return Math.atan2(sinTheta, cosTheta);
}
function animate() {
maxOrbitRadius = (canvas.width / 2) - margin;
const centerX = canvas.width / 2 + offsetX;
const centerY = canvas.height / 2 + offsetY;
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
const positions = planets.map(planet => {
const a = orbitRadius(planet.distance);
const e = planet.eccentricity;
const M = (2 * Math.PI * t) / planet.period;
const E = solveKepler(M, e);
const theta = getTrueAnomaly(E, e);
const r = a * (1 - e * e) / (1 + e * Math.cos(theta));
let x = r * Math.cos(theta);
let y = r * Math.sin(theta);
const inclination = planet.inclination;
y *= Math.cos(inclination);
return {
x: centerX + x * scale,
y: centerY + y * scale,
color: planet.color,
name: planet.name
};
});
const earthPos = positions[earthIndex];
ctx.strokeStyle = '#333';
ctx.lineWidth = 1;
ctx.setLineDash([3, 3]);
planets.forEach((planet, i) => {
if (!planetVisibility[i]) return;
const a = orbitRadius(planet.distance) * scale;
const e = planet.eccentricity;
const b = a * Math.sqrt(1 - e * e);
const inclination = planet.inclination;
const scaledB = b * Math.cos(inclination);
ctx.beginPath();
if (frame === 'sun') {
const focusOffset = a * e;
ctx.ellipse(centerX + focusOffset, centerY, a, scaledB, 0, 0, Math.PI * 2);
} else {
ctx.ellipse(earthPos.x, earthPos.y, a, scaledB, 0, 0, Math.PI * 2);
}
ctx.stroke();
});
ctx.setLineDash([]);
if (frame === 'sun') {
drawPoint(centerX, centerY, '#ffff00', 6);
} else {
drawPoint(centerX, centerY, '#008000', 6);
const sunX = centerX - (earthPos.x - centerX);
const sunY = centerY - (earthPos.y - centerY);
drawPoint(sunX, sunY, '#ffff00', 6);
}
positions.forEach((pos, i) => {
if (!planetVisibility[i]) return;
let drawX = pos.x;
let drawY = pos.y;
if (frame === 'earth') {
drawX = centerX + (pos.x - earthPos.x);
drawY = centerY + (pos.y - earthPos.y);
}
trajectories[i].push({x: drawX, y: drawY});
if (trajectories[i].length > 300) {
trajectories[i].shift();
}
if (trajectories[i].length > 1) {
ctx.beginPath();
ctx.strokeStyle = pos.color;
ctx.lineWidth = 1.5;
for (let j = 0; j < trajectories[i].length; j++) {
const p = trajectories[i][j];
if (j === 0) ctx.moveTo(p.x, p.y);
else ctx.lineTo(p.x, p.y);
}
ctx.stroke();
}
drawPoint(drawX, drawY, pos.color, 3);
});
ctx.fillStyle = '#fff';
ctx.font = '14px monospace';
ctx.textAlign = 'center';
const infoText = `Scale: ${scale.toFixed(2)}x | Speed: ${dt.toFixed(1)}dpf`;
ctx.fillText(infoText, canvas.width / 2, 12);
if (!isPaused) {
t += dt;
datePicker.value = getCurrentDate();
if (t > 100000) t = 0;
requestAnimationFrame(animate);
}
}
animate();
function toggleDonate() {
const info = document.getElementById("cryptoInfo");
const isOpening = info.style.display !== "flex";
info.style.display = isOpening ? "flex" : "none";
if (isOpening) {
setTimeout(() => info.scrollIntoView({ behavior: 'smooth', block: 'nearest' }), 50);
}
}
function copyToClipboard() {
const addr = document.getElementById("cryptoAddr");
const hint = document.getElementById("copyHint");
const text = addr.innerText;
navigator.clipboard.writeText(text).then(() => {
addr.innerText = "Copied!";
addr.style.color = "#00ff00";
if (hint) hint.innerText = "Address saved to clipboard";
setTimeout(() => {
addr.innerText = text;
addr.style.color = "#fff";
if (hint) hint.innerText = "Click address to copy";
}, 1500);
});
}
</script>
<footer>
<div class="donate-box">
<button class="donate-btn" onclick="toggleDonate()">Support</button>
<div id="cryptoInfo" class="crypto-info">
<span style="font-size: 10px; color: #fff; margin-bottom: 4px;">USDT BSC (BEP20)</span>
<div id="cryptoAddr" class="crypto-address-display" onclick="copyToClipboard()">0x769192cea8fbb7207f086d95fd653ebc3adb0c72</div>
<span id="copyHint" style="font-size: 9px; color: #fff; margin-top: 4px;">Click address to copy</span>
</div>
</div>
</footer>
</body>
</html>