-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2663 lines (2466 loc) · 109 KB
/
index.html
File metadata and controls
2663 lines (2466 loc) · 109 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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>Sonnensystem-Simulator — N-Körper-Gravitation</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { background: #000; color: #ccc; font-family: 'Segoe UI', monospace; overflow: hidden; width: 100%; height: 100vh; touch-action: none; }
canvas { display: block; cursor: crosshair; width: 100%; height: 100%; }
/* Sidebar */
#sidebar {
position: absolute; top: 0; left: 0; width: 340px; height: 100vh;
background: rgba(10,12,20,0.94); border-right: 1px solid #2a2a3a;
overflow-y: auto; padding: 14px; z-index: 10;
scrollbar-width: thin; scrollbar-color: #444 #111;
-webkit-overflow-scrolling: touch;
}
#sidebar h2 { color: #7af; font-size: 15px; margin: 14px 0 6px; border-bottom: 1px solid #333; padding-bottom: 4px; }
#sidebar h2:first-child { margin-top: 0; }
#sidebar label { display: block; font-size: 12px; margin-top: 8px; color: #999; }
#sidebar input[type=range], #sidebar select {
width: 100%; font-size: 14px; background: #1a1a2e; color: #ddd; border: 1px solid #333; padding: 6px;
-webkit-appearance: none; appearance: none;
min-height: 32px; /* touch target */
}
#sidebar input[type=range] {
height: 32px; padding: 0; cursor: pointer;
-webkit-appearance: none; appearance: none;
}
#sidebar input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none; appearance: none;
width: 24px; height: 24px; border-radius: 50%;
background: #7af; cursor: pointer; border: 2px solid #335;
}
#sidebar input[type=range]::-moz-range-thumb {
width: 24px; height: 24px; border-radius: 50%;
background: #7af; cursor: pointer; border: 2px solid #335;
}
#sidebar .val { color: #7af; font-size: 12px; float: right; }
button {
background: #2a4a6a; color: #dde; border: 1px solid #4a6a8a;
padding: 10px 14px; font-size: 14px; cursor: pointer; border-radius: 5px;
margin: 3px 2px; min-height: 40px; min-width: 40px; /* touch target */
-webkit-tap-highlight-color: transparent;
}
button:hover { background: #3a6a9a; }
button:active { background: #4a7aba; transform: scale(0.97); }
button.danger { background: #6a2a2a; border-color: #8a4a4a; }
button.danger:hover { background: #9a3a3a; }
button.active { background: #4a6a2a; border-color: #6a8a4a; }
button.has-pending { background: #8a6a2a; border-color: #bb9944; }
/* Eingabefeld mit noch nicht uebernommener Aenderung */
.pending { border-color: #ddaa44 !important; background: #2e2818 !important; }
#help-toggle {
position: absolute; top: 8px; right: 8px; z-index: 20;
width: 32px; height: 32px; display: flex; align-items: center;
justify-content: center; cursor: pointer; font-size: 18px;
background: #222; border: 1px solid #444; color: #ffd866;
border-radius: 4px; user-select: none;
-webkit-tap-highlight-color: transparent;
}
#help-toggle:hover { background: #333; border-color: #555; }
#info-panel {
position: absolute; top: 48px; right: 8px;
background: rgba(10,12,20,0.95); border: 1px solid #2a2a3a;
padding: 10px 14px; font-size: 12px; z-index: 19; color: #aaa;
max-width: 280px; border-radius: 4px;
height: auto; max-height: 220px; overflow-y: auto;
display: none; line-height: 1.5;
}
#info-panel.show { display: block; }
#info-panel span { color: #7af; }
#perturber-info {
position: absolute; top: 10px; right: 10px;
background: rgba(10,12,20,0.85); border: 1px solid #2a2a3a;
padding: 8px 12px; font-size: 11px; z-index: 10; color: #f88;
display: none;
}
#toggle-sidebar {
position: absolute; top: 8px; left: 348px; z-index: 20;
background: #222; border: 1px solid #444; color: #aaa; width: 32px; height: 32px;
display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 14px;
border-radius: 4px;
}
#sidebar.collapsed { display: none; }
#toggle-sidebar.shifted { left: 8px; }
/* Mobile overlay buttons */
#mobile-controls {
display: none;
position: absolute; bottom: 10px; left: 10px;
z-index: 15;
}
#mobile-controls button {
width: 48px; height: 48px; border-radius: 50%;
font-size: 20px; margin: 3px; display: inline-flex;
align-items: center; justify-content: center;
}
/* Floating-Inject-Button — unten mittig, auf Desktop UND Mobile sichtbar.
Prominent platziert weil "Rogue injizieren" die Hauptinteraktion
ist und in der Sidebar/im Sheet schnell aus dem Blickfeld geraet. */
#float-inject {
position: absolute; bottom: 40px; right: 16px;
z-index: 16;
width: 56px; height: 56px; border-radius: 50%;
background: #aa3333; border: 2px solid #cc5555; color: #fff;
font-size: 24px;
display: flex; align-items: center; justify-content: center;
cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.6);
-webkit-tap-highlight-color: transparent;
}
#float-inject:hover { background: #cc4444; }
#float-inject:active { background: #dd5555; }
/* Mobile settings panel — faehrt von links ein (wie die Desktop-Sidebar),
geoeffnet ueber den Schalter oben links. Nicht mehr von unten, damit es
nicht mit den Steuer-Buttons unten links konkurriert. */
#mobile-sheet {
display: none;
position: absolute; top: 0; left: 0; bottom: 0;
width: 86%; max-width: 340px;
background: rgba(10,12,20,0.97);
border-right: 1px solid #2a2a3a;
z-index: 18; overflow-y: auto;
-webkit-overflow-scrolling: touch;
touch-action: pan-y; /* vertikales Scrollen trotz body touch-action:none */
padding: 56px 12px 12px 12px;
transform: translateX(0);
transition: transform 0.2s ease;
}
#mobile-sheet.hidden { transform: translateX(-100%); }
#mobile-sheet h2 { color: #7af; font-size: 14px; margin: 10px 0 4px; border-bottom: 1px solid #333; padding-bottom: 3px; }
#mobile-sheet h2:first-child { margin-top: 0; }
#mobile-sheet label { display: block; font-size: 13px; margin-top: 6px; color: #999; }
#mobile-sheet input[type=range] {
width: 100%; height: 36px; -webkit-appearance: none; appearance: none;
background: #1a1a2e; border: 1px solid #333;
}
#mobile-sheet input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none; appearance: none;
width: 28px; height: 28px; border-radius: 50%;
background: #7af; cursor: pointer; border: 2px solid #335;
}
#mobile-sheet button { min-height: 44px; font-size: 14px; padding: 10px 14px; }
/* Mobile-Schalter oben links — oeffnet/schliesst das Einstellungs-Panel */
#mobile-menu-btn {
display: none;
position: absolute; top: 8px; left: 8px; z-index: 25;
width: 44px; height: 44px; border-radius: 6px;
background: #2a4a6a; border: 1px solid #4a6a8a; color: #dde;
font-size: 20px; align-items: center; justify-content: center;
cursor: pointer; -webkit-tap-highlight-color: transparent;
}
#mobile-menu-btn:active { background: #4a7aba; }
/* Responsive: tablet and below */
@media (max-width: 900px) {
#sidebar {
width: 300px;
}
#toggle-sidebar { left: 308px; }
#toggle-sidebar.shifted { left: 8px; }
}
@media (max-width: 700px) {
#sidebar { display: none !important; }
#toggle-sidebar { display: none !important; }
#mobile-controls { display: block; }
#mobile-sheet { display: block; }
#mobile-menu-btn { display: flex; }
#info-panel { font-size: 10px; bottom: 60px; right: 5px; padding: 6px 10px; max-width: 220px; }
}
/* Range slider track styling */
input[type=range] {
background: linear-gradient(to right, #335 0%, #335 50%, #1a1a2e 50%);
border-radius: 3px;
}
/* Footer mit Repo-Link + Stars */
#site-footer {
position: fixed; right: 8px; bottom: 6px;
z-index: 20; pointer-events: auto;
display: flex; gap: 8px; align-items: center;
font-size: 11px; color: #aaa;
background: rgba(10,12,20,0.55);
padding: 4px 8px; border-radius: 4px;
border: 1px solid rgba(80,80,100,0.25);
}
#site-footer a {
color: #aaa; text-decoration: none;
display: inline-flex; align-items: center; gap: 4px;
}
#site-footer a:hover { color: #7af; }
#gh-stars-wrap {
display: none; align-items: center; gap: 3px; color: #f3c969;
}
@media (max-width: 768px) {
#site-footer { font-size: 10px; bottom: 4px; right: 4px; padding: 3px 6px; }
#site-footer a span { display: none; } /* nur Icon auf Mobile */
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<!-- Desktop Sidebar -->
<div id="sidebar">
<details open style="margin-bottom:10px;">
<summary style="color:#7af; font-size:15px; font-weight:bold; cursor:pointer; padding-bottom:4px; border-bottom:1px solid #333;">🌌 Szenario</summary>
<select id="scenario-select" style="width:100%; margin-top:8px; font-size:14px; background:#1a1a2e; color:#ddd; border:1px solid #333; border-radius:4px; padding:6px; min-height:34px;">
<option>Sonnensystem</option>
<option>Trisolaris (3 Sonnen)</option>
<option>Lagrange (instabil)</option>
<option>Lagrange (stabil)</option>
<option>Trojaner (L4)</option>
<option>Figur 8 (Choreografie)</option>
<option>Butterfly I</option>
<option>Moth I</option>
<option>Goggles</option>
<option>Yarn</option>
<option>Leeres System</option>
<option>TRAPPIST-1</option>
<option>Alpha Centauri</option>
<option>Kepler-16</option>
<option>Kepler-47 (Doppelstern, 3 Planeten)</option>
</select>
<div style="display:flex; gap:4px; margin-top:6px;">
<button id="btn-save-cfg" style="flex:1; font-size:11px; padding:6px 3px; min-height:auto; min-width:auto;">Speichern</button>
<button id="btn-export-cfg" style="flex:1; font-size:11px; padding:6px 3px; min-height:auto; min-width:auto;">Export</button>
<button id="btn-import-cfg" style="flex:1; font-size:11px; padding:6px 3px; min-height:auto; min-width:auto;">Import</button>
</div>
<input type="file" id="import-file" accept=".json,application/json" style="display:none;">
</details>
<h2>⚙ Zeitsteuerung</h2>
<label>Zeitschritt (Tage/Schritt) <span class="val" id="dt-val">1</span></label>
<input type="range" autocomplete="off"id="dt-slider" min="0.1" max="50" step="0.1" value="1">
<label>Verlangsamung <span class="val" id="slow-val">1.0×</span></label>
<input type="range" autocomplete="off"id="slow-slider" min="-1" max="2" step="0.05" value="0">
<div style="margin-top:6px">
<button id="btn-pause">⏸ Pause</button>
<button id="btn-step">⏭ Schritt</button>
<button id="btn-reset">↻ Reset</button>
</div>
<h2>🔭 Anzeige</h2>
<label>Zoom <span class="val" id="zoom-val">0.35</span></label>
<input type="range" autocomplete="off"id="zoom-slider" min="0.05" max="500" step="0.05" value="0.35">
<label>
<input type="checkbox" id="chk-trails" checked> Bahnspuren anzeigen
</label>
<label>Bahnspur-Länge <span class="val" id="trail-val">150</span></label>
<input type="range" autocomplete="off"id="trail-slider" min="50" max="3000" step="50" value="150">
<label>
<input type="checkbox" id="chk-vectors"> Kraftvektoren anzeigen
</label>
<label>
<input type="checkbox" id="chk-grid" checked> Gitternetz
</label>
<label>
<input type="checkbox" id="chk-logzoom" checked> Logarithmischer Zoom
</label>
<label>
<input type="checkbox" id="chk-baryctr" checked> Schwerpunkt zentrieren
</label>
<label>Sichtbare Körper:</label>
<div id="planet-checks"></div>
<button id="btn-apply" style="width:100%; margin-top:8px;">✓ Änderungen übernehmen</button>
<h2>🪐 Rogue injizieren</h2>
<label>Masse <span class="val" id="p-mass-val">1,0 M⊕</span></label>
<input type="range" autocomplete="off"id="p-mass" min="-3" max="16" step="0.1" value="0">
<label>Start: Mausposition auf Canvas klicken</label>
<label>Geschwindigkeit (km/s) <span class="val" id="p-speed-val">30</span></label>
<input type="range" autocomplete="off"id="p-speed" min="0" max="100" step="1" value="30">
<label title="Kompass-Kurs: 0°=N, 90°=O, 180°=S, 270°=W">Kompass-Kurs (°) <span class="val" id="p-angle-val">270°</span></label>
<input type="range" autocomplete="off"id="p-angle" min="0" max="360" step="1" value="270" title="0°=N, 90°=O, 180°=S, 270°=W">
<label>Oder: Klick + Ziehen auf Canvas = Vektor</label>
<div>
<button id="btn-inject">🪐 Injizieren</button>
<button id="btn-clear-pert" class="danger">Alle Rogues löschen</button>
</div>
<div id="perturber-list" style="font-size:11px; color:#f88; margin-top:6px;"></div>
<h2>📊 Statistik</h2>
<div id="stats" style="font-size:11px;"></div>
</div>
<div id="toggle-sidebar" title="Sidebar ein/ausblenden">◀</div>
<div id="help-toggle" title="Steuerung anzeigen">💡</div>
<div id="info-panel">
Mausrad: Zoom | Rechts-/Mittelklick: Verschieben<br>
Linksklick: Rogue-Position wählen<br>
Klick+Ziehen: Geschwindigkeitsvektor setzen<br>
Touch: 2-Finger=Zoom/Pan, 1-Finger lang halten=Rogue<br>
<span>Taste:</span> P=Pause, R=Reset, Space=Schritt<br>
<span style="color:#7af;">Einheiten:</span> M⊕ = Erdmasse (5,97 · 10<sup>24</sup> kg) |
M⊙ = Sonnenmasse (1,99 · 10<sup>30</sup> kg, ≈ 333.000 M⊕)
</div>
<div id="perturber-info"></div>
<!-- Mobile Controls (visible on small screens) -->
<div id="mobile-controls">
<button id="mob-pause" title="Pause">⏸</button>
<button id="mob-zoom-in" title="Zoom +" style="font-size:24px;">+</button>
<button id="mob-zoom-out" title="Zoom −" style="font-size:24px;">−</button>
<button id="mob-reset" title="Reset">↻</button>
</div>
<!-- Floating-Inject-Button — auf allen Bildschirmgrößen sichtbar -->
<button id="float-inject" title="Rogue injizieren">🪐</button>
<!-- Mobile Bottom Sheet -->
<div id="mobile-sheet" class="hidden">
<details open style="margin-bottom:10px;">
<summary style="color:#7af; font-size:14px; font-weight:bold; cursor:pointer;">🌌 Szenario</summary>
<select id="mob-scenario-select" style="width:100%; margin-top:6px; font-size:14px; background:#1a1a2e; color:#ddd; border:1px solid #333; border-radius:4px; padding:6px; min-height:36px;">
<option>Sonnensystem</option>
<option>Trisolaris (3 Sonnen)</option>
<option>Lagrange (instabil)</option>
<option>Lagrange (stabil)</option>
<option>Trojaner (L4)</option>
<option>Figur 8 (Choreografie)</option>
<option>Butterfly I</option>
<option>Moth I</option>
<option>Goggles</option>
<option>Yarn</option>
<option>Leeres System</option>
<option>TRAPPIST-1</option>
<option>Alpha Centauri</option>
<option>Kepler-16</option>
<option>Kepler-47 (Doppelstern, 3 Planeten)</option>
</select>
<div style="display:flex; gap:4px; margin-top:6px;">
<button id="mob-btn-save-cfg" style="flex:1; font-size:12px;">Speichern</button>
<button id="mob-btn-export-cfg" style="flex:1; font-size:12px;">Export</button>
<button id="mob-btn-import-cfg" style="flex:1; font-size:12px;">Import</button>
</div>
</details>
<h2>⚙ Zeitsteuerung</h2>
<label>Zeitschritt (Tage) <span class="val" id="mob-dt-val">1</span></label>
<input type="range" autocomplete="off"id="mob-dt-slider" min="0.1" max="50" step="0.1" value="1">
<label>Verlangsamung <span class="val" id="mob-slow-val">1.0×</span></label>
<input type="range" autocomplete="off"id="mob-slow-slider" min="-1" max="2" step="0.05" value="0">
<h2>🔭 Anzeige</h2>
<label>Zoom <span class="val" id="mob-zoom-val">0.35</span></label>
<input type="range" autocomplete="off"id="mob-zoom-slider" min="0.05" max="500" step="0.05" value="0.35">
<label><input type="checkbox" id="mob-chk-trails" checked> Bahnspuren</label>
<label>Bahnspur-Länge <span class="val" id="mob-trail-val">150</span></label>
<input type="range" autocomplete="off"id="mob-trail-slider" min="50" max="3000" step="50" value="150">
<label><input type="checkbox" id="mob-chk-vectors"> Kraftvektoren</label>
<label><input type="checkbox" id="mob-chk-grid" checked> Gitternetz</label>
<label><input type="checkbox" id="mob-chk-logzoom" checked> Log-Zoom</label>
<label><input type="checkbox" id="mob-chk-baryctr" checked> Schwerpunkt zentrieren</label>
<label>Sichtbare Körper:</label>
<div id="mob-planet-checks"></div>
<button id="mob-btn-apply" style="width:100%; margin-top:8px;">✓ Änderungen übernehmen</button>
<h2>🪐 Rogue</h2>
<label>Masse <span class="val" id="mob-p-mass-val">1,0 M⊕</span></label>
<input type="range" autocomplete="off"id="mob-p-mass" min="-3" max="16" step="0.1" value="0">
<label>Geschwindigkeit (km/s) <span class="val" id="mob-p-speed-val">30</span></label>
<input type="range" autocomplete="off"id="mob-p-speed" min="0" max="100" step="1" value="30">
<label title="Kompass-Kurs: 0°=N, 90°=O, 180°=S, 270°=W">Kompass-Kurs (°) <span class="val" id="mob-p-angle-val">270°</span></label>
<input type="range" autocomplete="off"id="mob-p-angle" min="0" max="360" step="1" value="270" title="0°=N, 90°=O, 180°=S, 270°=W">
<label style="color:#faa; font-size:11px;">Tipp: 1-Finger auf Canvas tippen & ziehen = Position + Vektor</label>
<div style="margin-top:8px;">
<button id="mob-inject">🪐 Injizieren</button>
<button id="mob-clear-pert" class="danger">Löschen</button>
</div>
<div id="mob-perturber-list" style="font-size:11px; color:#f88; margin-top:6px;"></div>
<h2>📊 Statistik</h2>
<div id="mob-stats" style="font-size:11px;"></div>
</div>
<div id="mobile-menu-btn" title="Einstellungen">☰</div>
<script>
// ============================================================
// SONNENSYSTEM N-KÖRPER-SIMULATION
// Newtonsche Gravitation + Velocity Verlet-Integration
// Mobil-optimiert mit Touch-Support
// ============================================================
const G_SI = 6.674e-11;
const AU = 1.495978707e11;
const DAY = 86400;
const M_EARTH = 5.972e24;
const M_SUN = 1.98842e30;
const G_AU = 4 * Math.PI * Math.PI;
// 1 km/s in AU/Jahr: (1 km / 1 AU) * (Sekunden pro Jahr) ≈ 0.2109
const KM_S_TO_AU_YR = (1000 / AU) * (365.25 * DAY);
// Maximaler Sub-Zeitschritt (Jahre) — haelt die innerste Bahn glatt
const MAX_SUB_DT_YEARS = 0.5 / 365.25;
// Ab dieser Masse (Sonnenmassen) gilt ein Koerper als Stern — die
// Mindestmasse fuer Wasserstoff-Fusion liegt bei ~0.08 M_sonne.
const STAR_MASS_THRESHOLD = 0.08;
// Schwelle fuer Schwarze-Loch-Darstellung: oberhalb des massereichsten
// beobachteten Hauptreihensterns (BAT99-98 ≈ 226 M_sonne, R136a1 ≈ 196).
// Lebende Sterne koennen theoretisch bis ~300 M_sonne existieren (Pair-
// Instability-Region 130–250), darueber direkter Kollaps zum SL.
const BH_MASS_THRESHOLD = 230.0;
// Ab diesem Sonnenabstand (AU) gilt ein ungebundenes Objekt als
// "auf Fluchtkurs" — weit jenseits der Neptunbahn (~30 AU).
const ESCAPE_MARK_AU = 45;
// rkm = echter physikalischer Radius in km (fuer die Kollisionsphysik).
const PLANET_DATA = [
{ name: "Sonne", mass: 1.0, color: "#ffdd44", a: 0, ecc: 0, rkm: 696000 },
{ name: "Merkur", mass: 1.660e-7, color: "#aaaaaa", a: 0.3871, ecc: 0.2056, rkm: 2440 },
{ name: "Venus", mass: 2.447e-6, color: "#e8cda0", a: 0.7233, ecc: 0.0068, rkm: 6052 },
{ name: "Erde", mass: 3.003e-6, color: "#4488ff", a: 1.0000, ecc: 0.0167, rkm: 6371 },
{ name: "Mars", mass: 3.229e-7, color: "#dd5533", a: 1.5237, ecc: 0.0934, rkm: 3390 },
{ name: "Jupiter", mass: 9.543e-4, color: "#ddaa77", a: 5.2026, ecc: 0.0484, rkm: 69911 },
{ name: "Saturn", mass: 2.855e-4, color: "#ddcc88", a: 9.5549, ecc: 0.0547, rkm: 58232 },
{ name: "Uranus", mass: 4.366e-5, color: "#88ccdd", a: 19.218, ecc: 0.0473, rkm: 25362 },
{ name: "Neptun", mass: 5.151e-5, color: "#4466dd", a: 30.110, ecc: 0.0086, rkm: 24622 },
];
// Echte Radien & Ableitung aus der Masse (gleiche Dichte wie die Erde).
const M_EARTH_SUN = M_EARTH / M_SUN; // Erdmasse in Sonnenmassen
const R_EARTH_AU = 6371e3 / AU; // Erdradius in AU
function realRadiusFromMass(massSun) {
return R_EARTH_AU * Math.cbrt(Math.max(massSun, 1e-30) / M_EARTH_SUN);
}
// Einheitlicher Darstellungsradius aus der Masse (in Sonnenmassen).
// Gleiche Masse => gleiche Groesse, egal ob Planet, Sonne oder
// Stoermasse. Log-Mapping, weil die Massen ~8 Groessenordnungen
// ueberspannen (Merkur ~1.7e-7 M_sun .. Sonne 1.0 M_sun).
function massToRadius(massSun) {
const logM = Math.log10(Math.max(massSun, 1e-12));
const t = (logM + 8) / 8; // 1e-8 M_sun -> 0, 1.0 M_sun -> 1
return Math.max(1.5, Math.min(6, 1.5 + t * 4.5));
}
// Masse-Anzeige: Tausenderpunkte + Dezimalkomma, nie Exponentialschreibweise.
function formatMass(v) {
return v.toLocaleString('de-DE', { maximumFractionDigits: 6, useGrouping: true });
}
// Masse-Eingabe (deutsche Notation): Punkte = Tausender, Komma = Dezimal.
function parseMass(s) {
return parseFloat(String(s).replace(/\./g, '').replace(',', '.'));
}
// Zentrale Zahlenformatierung — Tausenderpunkte, Komma als Dezimal-
// trennzeichen, feste Nachkommastellen. Fuer alle UI-sichtbaren Zahlen
// verwenden (Statistik, Slider-Werte, Stoermassen-Info, Canvas-Texte).
function fmtDE(v, digits) {
if (!isFinite(v)) return String(v);
return v.toLocaleString('de-DE', {
minimumFractionDigits: digits,
maximumFractionDigits: digits,
useGrouping: true,
});
}
// Exponentialschreibweise mit Dezimalkomma (deutsche Notation).
function fmtDExp(v, digits) {
if (!isFinite(v)) return String(v);
return v.toExponential(digits).replace('.', ',');
}
// Masse-Anzeige in Erdmassen mit Sonnenmassen-Klammer:
// < 0,5 M☉ -> "1,0 M⊕"
// ≥ 0,5 M☉ bis 10⁵ M☉ -> "1.000.000 M⊕ (3,0 M☉)"
// > 10⁵ M☉ (schwere SLer) -> "2,2e+16 M⊕ (6,6e+10 M☉)"
// Ab BH_MASS_THRESHOLD wird zusätzlich "⚫ SL" angehängt.
function fmtMassWithSun(earthMasses) {
const main = earthMasses >= 1e6 ? fmtDExp(earthMasses, 2)
: earthMasses >= 100 ? fmtDE(earthMasses, 0)
: fmtDE(earthMasses, 1);
const sun = earthMasses * M_EARTH / M_SUN;
let result = main + ' M⊕';
if (sun >= 0.5) {
const sunStr = sun >= 1e5 ? fmtDExp(sun, 2)
: sun >= 100 ? fmtDE(sun, 0)
: sun >= 10 ? fmtDE(sun, 1)
: fmtDE(sun, 2);
result += ' (' + sunStr + ' M☉)';
}
if (sun >= BH_MASS_THRESHOLD) result += ' ⚫ SL';
return result;
}
// Canvas
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let W, H;
// Sichtbare Canvas-Mitte: die Sidebar verdeckt links einen Streifen, also
// wandert die nutzbare Mitte nach rechts. Geschlossene Sidebar / mobil:
// getBoundingClientRect().width ist 0 (display:none) -> Mitte = W/2.
let viewCX = window.innerWidth / 2;
function updateViewCenter() {
const sb = document.getElementById('sidebar');
const w = sb ? sb.getBoundingClientRect().width : 0;
viewCX = (w + W) / 2;
}
function resize() {
W = canvas.width = window.innerWidth;
H = canvas.height = window.innerHeight;
updateViewCenter();
}
resize();
window.addEventListener('resize', resize);
// --- Simulation ---
let bodies = [];
let trails = {};
let MAX_TRAIL = 150; // per Slider konfigurierbare Bahnspur-Laenge
// ============================================================
// SZENARIEN
// ============================================================
let currentScenario = 'Sonnensystem';
// Koerper mit Standardfeldern in bodies + trails einhaengen.
function pushBody(o) {
bodies.push({
name: o.name, mass: o.mass,
x: o.x, y: o.y, vx: o.vx || 0, vy: o.vy || 0, ax: 0, ay: 0,
color: o.color, radius: massToRadius(o.mass),
realR: o.rkm ? o.rkm * 1000 / AU : realRadiusFromMass(o.mass),
visible: true, isStar: !!o.isStar, escapeScore: 0,
});
trails[o.name] = [];
}
// Alle Koerper ins Schwerpunkt-Ruhesystem schieben: Gesamtimpuls = 0,
// Schwerpunkt im Ursprung. Funktioniert fuer beliebig viele Sterne.
function centerOfMassCorrection() {
let px=0, py=0, cx=0, cy=0, mt=0;
for (const b of bodies) {
px += b.mass*b.vx; py += b.mass*b.vy;
cx += b.mass*b.x; cy += b.mass*b.y; mt += b.mass;
}
if (mt <= 0) return;
px/=mt; py/=mt; cx/=mt; cy/=mt;
for (const b of bodies) {
b.vx -= px; b.vy -= py;
b.x -= cx; b.y -= cy;
}
}
// Planet auf Kepler-Ellipse (Perihel-Start) um eine Zentralmasse M
// im Ursprung. p: {name, mass, color, a, ecc, rkm}
function planetOnOrbit(p, M) {
const rPeri = p.a * (1 - p.ecc);
const vPeri = Math.sqrt(G_AU * M * (1 + p.ecc) / (p.a * (1 - p.ecc)));
const ang = Math.random() * Math.PI * 2;
pushBody({
name: p.name, mass: p.mass, color: p.color, rkm: p.rkm, isStar: !!p.isStar,
x: rPeri*Math.cos(ang), y: rPeri*Math.sin(ang),
vx: -vPeri*Math.sin(ang), vy: vPeri*Math.cos(ang),
});
}
// Zwei Sterne auf gemeinsamer Kepler-Ellipse um ihren Schwerpunkt.
function buildBinary(s1, s2, a, ecc) {
const mt = s1.mass + s2.mass;
const rPeri = a * (1 - ecc);
const vRel = Math.sqrt(G_AU * mt * (1 + ecc) / (a * (1 - ecc)));
pushBody({ ...s1, isStar:true, x: rPeri*s2.mass/mt, y:0, vx:0, vy: vRel*s2.mass/mt });
pushBody({ ...s2, isStar:true, x: -rPeri*s1.mass/mt, y:0, vx:0, vy: -vRel*s1.mass/mt });
}
function buildSolarSystem() {
const sun = PLANET_DATA[0];
pushBody({ name:sun.name, mass:sun.mass, color:sun.color, rkm:sun.rkm,
x:0, y:0, vx:0, vy:0, isStar:true });
for (let i = 1; i < PLANET_DATA.length; i++) planetOnOrbit(PLANET_DATA[i], sun.mass);
}
function buildEmpty() { /* leer — Koerper per Klick setzen (Bau-Modus) */ }
function buildTrappist() {
const sm = 0.0898; // Sternmasse in Sonnenmassen
pushBody({ name:'TRAPPIST-1', mass:sm, color:'#ff6644', rkm:83000,
x:0, y:0, vx:0, vy:0, isStar:true });
// [Name, a (AU), Masse (Erdmassen), ecc] — Agol et al. 2021
const pl = [
['b',0.01154,1.374,0.006], ['c',0.01580,1.308,0.007],
['d',0.02227,0.388,0.008], ['e',0.02925,0.692,0.005],
['f',0.03849,1.039,0.010], ['g',0.04683,1.321,0.002],
['h',0.06189,0.326,0.006],
];
const cols = ['#88ccff','#aaddcc','#ddcc88','#88ddaa','#ffcc99','#ccaaee','#aabbdd'];
pl.forEach(([n,a,me,e],i) => planetOnOrbit({
name:'TRAPPIST-1'+n, mass:me*M_EARTH_SUN, color:cols[i],
a:a, ecc:e, rkm:6371*Math.cbrt(me) }, sm));
}
function buildAlphaCentauri() {
buildBinary(
{ name:'α Centauri A', mass:1.079, color:'#fff0cc', rkm:851000 },
{ name:'α Centauri B', mass:0.909, color:'#ffddaa', rkm:601000 },
23.5, 0.518);
}
function buildKepler16() {
const mA = 0.6897, mB = 0.20255;
buildBinary(
{ name:'Kepler-16 A', mass:mA, color:'#ffddaa', rkm:451600 },
{ name:'Kepler-16 B', mass:mB, color:'#ff8866', rkm:157000 },
0.224, 0.159);
// zirkumbinaerer Planet — umkreist den gemeinsamen Schwerpunkt
planetOnOrbit({ name:'Kepler-16 b', mass:105.8*M_EARTH_SUN, color:'#bb9977',
a:0.7048, ecc:0.0069, rkm:53800 }, mA + mB);
}
function buildKepler47() {
// Kepler-47 — erstes bekanntes Mehrplaneten-System um einen Doppelstern.
// Drei zirkumbinaere Planeten (Orosz et al. 2012/2019). Sternmassen und
// Bahnhalbachsen aus den Entdeckungsarbeiten; Planetenmassen sind nur
// grob bekannt (reine Transit-Daten) und dynamisch ohnehin vernachlaessigbar.
const mA = 1.043, mB = 0.362;
buildBinary(
{ name:'Kepler-47 A', mass:mA, color:'#fff4e0', rkm:668000 },
{ name:'Kepler-47 B', mass:mB, color:'#ff7a55', rkm:244000 },
0.0836, 0.023);
const mTot = mA + mB;
// a (AU) aus den Entdeckungsarbeiten, alle drei jenseits der Stabilitaets-
// grenze (~3.5x Doppelstern-Abstand) — daher langfristig stabil.
planetOnOrbit({ name:'Kepler-47 b', mass:10*M_EARTH_SUN, color:'#9fb8c4', a:0.2954, ecc:0.02, rkm:19100 }, mTot);
planetOnOrbit({ name:'Kepler-47 d', mass:25*M_EARTH_SUN, color:'#c8b48a', a:0.6992, ecc:0.02, rkm:44600 }, mTot);
planetOnOrbit({ name:'Kepler-47 c', mass:20*M_EARTH_SUN, color:'#a8cdd6', a:0.989, ecc:0.04, rkm:30000 }, mTot);
}
function buildTrisolaris() {
// Chaotisches Dreikoerpersystem aus Liu Cixins "Drei-Koerper-Problem".
const stars = [
{ name:'Sonne I', mass:1.0, color:'#ffdd44', rkm:696000, x: 0, y: 4, vx: 1.4, vy: 0 },
{ name:'Sonne II', mass:1.0, color:'#ff9944', rkm:696000, x:-3.5, y:-2, vx:-0.7, vy:-1.2 },
{ name:'Sonne III', mass:1.0, color:'#ffcc88', rkm:696000, x: 3.5, y:-2, vx:-0.7, vy: 1.2 },
];
for (const s of stars) pushBody({ ...s, isStar:true });
pushBody({ name:'Trisolaris', mass:3*M_EARTH_SUN, color:'#4488ff', rkm:8000,
x:0.5, y:0, vx:0, vy:5 });
}
function buildLagrange() {
// Echte Lagrange-Loesung (L4/L5): drei gleiche Massen an den Ecken eines
// gleichseitigen Dreiecks, das als Ganzes starr rotiert. Jede Sonne zieht
// einen exakten Kreis um den gemeinsamen Schwerpunkt — keine Pirouetten.
// Bedingung fuer rigide Rotation: omega^2 = 3*G*m / L^3, woraus die
// Bahngeschwindigkeit v = sqrt(G*m / L) folgt (m = Einzelmasse).
const m = 1.0; // Sonnenmassen je Stern
const L = 6; // Seitenlaenge des Dreiecks (AU)
const R = L / Math.sqrt(3); // Abstand jeder Sonne vom Schwerpunkt
const v = Math.sqrt(G_AU * m / L); // Bahngeschwindigkeit (AU/Jahr)
const colors = ['#ffdd44', '#ff9944', '#ffcc88'];
const roman = ['I', 'II', 'III'];
for (let k = 0; k < 3; k++) {
const ang = Math.PI/2 + k * 2*Math.PI/3; // 90, 210, 330 Grad
pushBody({
name: 'Lagrange ' + roman[k], mass: m, color: colors[k],
rkm: 696000, isStar: true,
x: R * Math.cos(ang), y: R * Math.sin(ang),
vx: -v * Math.sin(ang), vy: v * Math.cos(ang), // tangential, CCW
});
}
}
function buildLagrangeStable() {
// Stabile Lagrange-Loesung: eine schwere Zentralmasse, zwei leichte
// Begleiter. Erfuellt das Routh-Kriterium (1877):
// (m1+m2+m3)^2 >= 27*(m1*m2 + m2*m3 + m3*m1)
// Allgemeine rigide Rotation: omega^2 = G*M_gesamt / L^3.
const masses = [30, 0.5, 0.5]; // Sonnenmassen — 31 gesamt
const L = 8; // Seitenlaenge des Dreiecks (AU)
const Rg = L / Math.sqrt(3); // Eckenabstand vom Geometrie-Zentrum
const mTot = masses[0] + masses[1] + masses[2];
const omega = Math.sqrt(G_AU * mTot / (L*L*L)); // rigide Rotationsrate
// Eckpunkte des gleichseitigen Dreiecks
const pos = [];
for (let k = 0; k < 3; k++) {
const ang = Math.PI/2 + k * 2*Math.PI/3;
pos.push([Rg * Math.cos(ang), Rg * Math.sin(ang)]);
}
// Massenschwerpunkt — bei ungleichen Massen NICHT das Geometrie-Zentrum.
let cx = 0, cy = 0;
for (let k = 0; k < 3; k++) { cx += masses[k]*pos[k][0]; cy += masses[k]*pos[k][1]; }
cx /= mTot; cy /= mTot;
// Jeder Koerper rotiert mit omega um den Schwerpunkt: v = omega x r.
const colors = ['#ffeecc', '#ff8866', '#ffaa66'];
const roman = ['A', 'B', 'C'];
for (let k = 0; k < 3; k++) {
const rx = pos[k][0] - cx, ry = pos[k][1] - cy;
pushBody({
name: 'Lagrange ' + roman[k], mass: masses[k], color: colors[k],
rkm: k === 0 ? 2500000 : 350000, isStar: true,
x: pos[k][0], y: pos[k][1],
vx: -omega * ry, vy: omega * rx,
});
}
}
function buildTrojan() {
// Klassischer L4-Punkt im Wortsinn: Sonne + Jupiter auf Kreisbahn, dazu
// ein winziger Trojaner-Asteroid exakt 60 Grad VOR Jupiter. Die drei
// bilden ein gleichseitiges Dreieck und rotieren rigide mit
// omega^2 = G*M_gesamt / L^3.
// Massenverhaeltnis Sonne/Jupiter ~1000:1 erfuellt das Gascheau-
// Stabilitaetskriterium (>= 24.96) muehelos -> L4 ist stabil.
const M_JUP = 9.543e-4; // Jupitermasse in Sonnenmassen
const M_TRO = 1e-9; // Trojaner: gravitativ vernachlaessigbar
const L = 5.2; // Sonne-Jupiter-Abstand (AU)
const mTot = 1.0 + M_JUP + M_TRO;
const omega = Math.sqrt(G_AU * mTot / (L*L*L));
// Eckpunkte relativ zur Sonne: Jupiter bei 0 Grad, Trojaner 60 Grad voraus.
const def = [
{ name:'Sonne', mass:1.0, color:'#ffdd44', rkm:696000, isStar:true, x:0, y:0 },
{ name:'Jupiter', mass:M_JUP, color:'#ccaa88', rkm:69911, isStar:false, x:L, y:0 },
{ name:'Trojaner', mass:M_TRO, color:'#88ccff', rkm:120, isStar:false,
x:L*0.5, y:L*Math.sqrt(3)/2 },
];
// Massenschwerpunkt -> rigide Rotation: v = omega x (r - Schwerpunkt).
let cx = 0, cy = 0;
for (const d of def) { cx += d.mass*d.x; cy += d.mass*d.y; }
cx /= mTot; cy /= mTot;
for (const d of def) {
pushBody({
name:d.name, mass:d.mass, color:d.color, rkm:d.rkm, isStar:d.isStar,
x:d.x, y:d.y,
vx:-omega*(d.y-cy), vy:omega*(d.x-cx),
});
}
}
function buildFigure8() {
// Chenciner-Montgomery Figur-8-Choreografie (2000): drei gleiche Massen
// jagen einander auf EINER gemeinsamen 8-foermigen Bahn. Eine der wenigen
// linear STABILEN Choreografien. Kanonische Startwerte (Carles Simo)
// gelten fuer G=1, m=1; hier skaliert auf AU/Jahr/Sonnenmasse ueber
// die Massstabsrelation gamma^2 = alpha^3 / (G*m).
const m = 1.0; // Sonnenmassen je Koerper
const alpha = 3.0; // Laengenskala (AU) — Groesse der Acht
const gamma = Math.sqrt(alpha*alpha*alpha / (G_AU * m));
const vs = alpha / gamma; // Geschwindigkeitsskala
// Kanonische Figur-8-Startwerte
const px = 0.97000436, py = 0.24308753;
const vx = 0.4662036850, vy = 0.4323657300;
const def = [
{ name:'Acht I', x:-px, y: py, vx: vx, vy: vy },
{ name:'Acht II', x: px, y:-py, vx: vx, vy: vy },
{ name:'Acht III', x: 0, y: 0, vx:-2*vx, vy:-2*vy },
];
const colors = ['#88ccff', '#ffcc66', '#ff8888'];
for (let k = 0; k < 3; k++) {
const d = def[k];
pushBody({
name:d.name, mass:m, color:colors[k], rkm:696000, isStar:true,
x: alpha*d.x, y: alpha*d.y,
vx: vs*d.vx, vy: vs*d.vy,
});
}
}
// Suvakov-Dmitrasinovic-Choreografie (PRL 2013): drei gleiche Massen auf
// EINER gemeinsamen Bahn. Kanonische Startwerte (G=1, m=1): Koerper bei
// (-1,0),(1,0),(0,0), Geschwindigkeiten (v1,v2),(v1,v2),(-2v1,-2v2).
// Skaliert auf unsere Einheiten ueber gamma^2 = alpha^3 / (G*m).
function buildChoreography(v1, v2, alpha) {
const m = 1.0;
const gamma = Math.sqrt(alpha*alpha*alpha / (G_AU * m));
const vs = alpha / gamma;
const def = [
{ name:'Koerper I', x:-1, y:0, vx: v1, vy: v2 },
{ name:'Koerper II', x: 1, y:0, vx: v1, vy: v2 },
{ name:'Koerper III', x: 0, y:0, vx:-2*v1, vy:-2*v2 },
];
const colors = ['#88ccff', '#ffcc66', '#ff8888'];
for (let k = 0; k < 3; k++) {
const d = def[k];
pushBody({
name:d.name, mass:m, color:colors[k], rkm:696000, isStar:true,
x: alpha*d.x, y: alpha*d.y,
vx: vs*d.vx, vy: vs*d.vy,
});
}
}
// Pro Szenario: Aufbau-Funktion + sinnvolle Voreinstellungen.
// zoom = Kamera-Zoom im linearen Modus
// zoomLog = Kamera-Zoom im logarithmischen Modus (andere Skala!)
// dt = Zeitschritt Tage/Frame
// slow = Verlangsamungs-Slider-Wert (log10 des Faktors; 0 = 1x).
const SCENARIOS = {
'Sonnensystem': { build: buildSolarSystem, zoom: 0.35, zoomLog: 6.55, dt: 1, slow: 0 },
'Trisolaris (3 Sonnen)': { build: buildTrisolaris, zoom: 6.55, zoomLog: 6.55, dt: 0.5, slow: 0, injectAngle: 180 },
'Lagrange (instabil)': { build: buildLagrange, zoom: 6.55, zoomLog: 6.55, dt: 0.5, slow: 0 },
'Lagrange (stabil)': { build: buildLagrangeStable, zoom: 6.55, zoomLog: 6.55, dt: 0.5, slow: 0 },
'Trojaner (L4)': { build: buildTrojan, zoom: 0.6, zoomLog: 6.55, dt: 1, slow: 0 },
'Figur 8 (Choreografie)':{ build: buildFigure8, zoom: 0.8, zoomLog: 6.55, dt: 0.5, slow: 0 },
'Butterfly I': { build: () => buildChoreography(0.30689, 0.12551, 2.5), zoom: 0.8, zoomLog: 6.55, dt: 0.5, slow: 0 },
'Moth I': { build: () => buildChoreography(0.46444, 0.39606, 2.5), zoom: 0.55, zoomLog: 6.55, dt: 0.5, slow: 0 },
'Goggles': { build: () => buildChoreography(0.08330, 0.12789, 2.5), zoom: 0.7, zoomLog: 6.55, dt: 0.5, slow: 0 },
'Yarn': { build: () => buildChoreography(0.55906, 0.34919, 2.5), zoom: 0.9, zoomLog: 6.55, dt: 0.5, slow: 0 },
'Leeres System': { build: buildEmpty, zoom: 0.35, zoomLog: 6.55, dt: 1, slow: 0 },
'TRAPPIST-1': { build: buildTrappist, zoom: 96, zoomLog: 330, dt: 0.1, slow: Math.log10(7) },
'Alpha Centauri': { build: buildAlphaCentauri, zoom: 0.15, zoomLog: 6.55, dt: 5, slow: 0 },
'Kepler-16': { build: buildKepler16, zoom: 8, zoomLog: 30, dt: 0.5, slow: 0 },
'Kepler-47 (Doppelstern, 3 Planeten)': { build: buildKepler47, zoom: 6, zoomLog: 30, dt: 0.1, slow: 0 },
};
// Liefert den Szenario-Zoom passend zum aktiven Modus (linear vs. log).
function scenarioZoom(name) {
const sc = SCENARIOS[name];
if (!sc) return useLogZoom ? 6.55 : 0.35;
return useLogZoom ? sc.zoomLog : sc.zoom;
}
function initBodies() {
bodies = [];
trails = {};
(SCENARIOS[currentScenario] || SCENARIOS['Sonnensystem']).build();
centerOfMassCorrection();
computeAccelerations();
computeTrailInterval();
}
// Koerper-Liste-UI (Checkboxen + Masse/Geschw.-Felder) neu aufbauen.
function rebuildBodyList() {
[checkDiv, mobCheckDiv].forEach(c => { c.innerHTML = ''; });
for (const b of bodies) {
addPlanetCheckbox(b, checkDiv);
addPlanetCheckbox(b, mobCheckDiv);
}
updatePerturberList();
updateApplyButton();
}
// Szenario laden: Koerper neu aufbauen + Koerper-Liste-UI neu erzeugen.
function loadScenario(name) {
currentScenario = name;
perturbers = [];
perturberCounter = 0;
fragmentCounter = 0;
simTime = 0;
realElapsedMs = 0; lastTickMs = 0;
injectMarked = false;
initBodies();
rebuildBodyList();
}
// ============================================================
// KONFIGURATIONEN SPEICHERN / LADEN
// ============================================================
// Aktuellen Zustand (alle Koerper + Ansicht) als serialisierbares Objekt.
function captureState() {
return {
v: 1,
zoom: cam.zoom,
logZoom: useLogZoom,
dt: parseFloat(document.getElementById('dt-slider').value),
slow: parseFloat(document.getElementById('slow-slider').value),
bodies: bodies.map(b => ({
name: b.name, mass: b.mass, x: b.x, y: b.y, vx: b.vx, vy: b.vy,
color: b.color, isStar: b.isStar, realR: b.realR, visible: b.visible,
})),
};
}
// Zustand wiederherstellen — ersetzt alle Koerper.
function restoreState(state) {
if (!state || !Array.isArray(state.bodies)) return false;
bodies = [];
trails = {};
for (const s of state.bodies) {
bodies.push({
name: s.name, mass: s.mass, x: s.x, y: s.y, vx: s.vx, vy: s.vy,
ax: 0, ay: 0, color: s.color, radius: massToRadius(s.mass),
realR: s.realR != null ? s.realR : realRadiusFromMass(s.mass),
visible: s.visible !== false, isStar: !!s.isStar, escapeScore: 0,
});
trails[s.name] = [];
}
perturbers = []; perturberCounter = 0; fragmentCounter = 0;
simTime = 0; injectMarked = false;
realElapsedMs = 0; lastTickMs = 0;
computeAccelerations();
computeTrailInterval();
rebuildBodyList();
// Zoom-Modus mitrestaurieren: der gespeicherte zoom-Wert gilt fuer genau
// diesen Modus (lineare und log. Skala sind nicht vergleichbar).
if (state.logZoom != null) {
useLogZoom = state.logZoom;
document.getElementById('chk-logzoom').checked = useLogZoom;
document.getElementById('mob-chk-logzoom').checked = useLogZoom;
try { localStorage.setItem('sim_useLogZoom', useLogZoom ? '1' : '0'); } catch (e) {}
}
if (state.zoom) applyZoom(state.zoom);
if (state.dt) applyDt(state.dt);
if (state.slow != null) applySlow(state.slow);
return true;
}
function savedConfigNames() {
try { return JSON.parse(localStorage.getItem('sim_cfg_index') || '[]'); }
catch (e) { return []; }
}
function saveConfig() {
const name = prompt('Name für diese Konfiguration:');
if (!name) return;
try {
localStorage.setItem('sim_cfg_' + name, JSON.stringify(captureState()));
const idx = savedConfigNames();
if (!idx.includes(name)) {
idx.push(name);
localStorage.setItem('sim_cfg_index', JSON.stringify(idx));
}
refreshScenarioOptions();
document.getElementById('scenario-select').value = '★ ' + name;
document.getElementById('mob-scenario-select').value = '★ ' + name;
} catch (e) { alert('Speichern fehlgeschlagen: ' + e); }
}
function exportConfig() {
const blob = new Blob([JSON.stringify(captureState(), null, 1)],
{ type: 'application/json' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'simulator-konfiguration.json';
a.click();
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
}
function importConfig(file) {
const reader = new FileReader();
reader.onload = () => {
try {
if (restoreState(JSON.parse(reader.result))) {
cam.cx = 0; cam.cy = 0;
} else {
alert('Datei enthält keine gültige Konfiguration.');
}
} catch (e) { alert('Import fehlgeschlagen: ' + e); }
};
reader.readAsText(file);
}
// Szenario-Auswahl neu befuellen: Presets + gespeicherte Konfigurationen.
function refreshScenarioOptions() {
const saved = savedConfigNames();
for (const id of ['scenario-select', 'mob-scenario-select']) {
const sel = document.getElementById(id);
const cur = sel.value;
sel.innerHTML = '';
for (const name of Object.keys(SCENARIOS)) {
const o = document.createElement('option');
o.textContent = name; sel.appendChild(o);
}
for (const name of saved) {
const o = document.createElement('option');
o.textContent = '★ ' + name; sel.appendChild(o);
}
if (cur) sel.value = cur;
}
}
function computeAccelerations() {
const G = G_AU;
const softening = 1e-6;
for (let i = 0; i < bodies.length; i++) {
bodies[i].ax = 0; bodies[i].ay = 0;
}
for (let i = 0; i < bodies.length; i++) {
if (!bodies[i].visible) continue; // ausgeschaltete Koerper: keine Gravitation
for (let j = i + 1; j < bodies.length; j++) {
if (!bodies[j].visible) continue;
const dx = bodies[j].x - bodies[i].x;
const dy = bodies[j].y - bodies[i].y;
const r2 = dx*dx + dy*dy + softening;
const r = Math.sqrt(r2);
const f = G / (r2 * r);
bodies[i].ax += f * bodies[j].mass * dx;
bodies[i].ay += f * bodies[j].mass * dy;
bodies[j].ax -= f * bodies[i].mass * dx;