trysem commited on
Commit
9736163
·
verified ·
1 Parent(s): a33c872

Create rahuketu3

Browse files
Files changed (1) hide show
  1. rahuketu3 +542 -0
rahuketu3 ADDED
@@ -0,0 +1,542 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Rahu & Ketu: The Lunar Nodes</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
10
+ <style>
11
+ body { margin: 0; overflow: hidden; background-color: #030308; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: white; }
12
+ #canvas-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }
13
+ #ui-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; pointer-events: none; }
14
+ .pointer-events-auto { pointer-events: auto; }
15
+
16
+ /* Glassmorphism panel */
17
+ .glass-panel {
18
+ background: rgba(15, 20, 35, 0.7);
19
+ backdrop-filter: blur(12px);
20
+ -webkit-backdrop-filter: blur(12px);
21
+ border: 1px solid rgba(255, 255, 255, 0.1);
22
+ box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
23
+ }
24
+
25
+ /* Custom Scrollbar for text panel */
26
+ ::-webkit-scrollbar { width: 6px; }
27
+ ::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); }
28
+ ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }
29
+ ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }
30
+
31
+ input[type=range] {
32
+ -webkit-appearance: none; background: transparent;
33
+ }
34
+ input[type=range]::-webkit-slider-thumb {
35
+ -webkit-appearance: none; height: 16px; width: 16px; border-radius: 50%;
36
+ background: #4ade80; cursor: pointer; margin-top: -6px;
37
+ }
38
+ input[type=range]::-webkit-slider-runnable-track {
39
+ width: 100%; height: 4px; cursor: pointer; background: rgba(255,255,255,0.2); border-radius: 2px;
40
+ }
41
+ </style>
42
+ </head>
43
+ <body>
44
+
45
+ <!-- 3D Canvas -->
46
+ <div id="canvas-container"></div>
47
+
48
+ <!-- UI Overlay -->
49
+ <div id="ui-layer" class="flex flex-col md:flex-row justify-between p-4 md:p-6 h-screen relative">
50
+
51
+ <!-- Left Info Panel -->
52
+ <div class="glass-panel w-full md:w-96 rounded-2xl p-6 flex flex-col pointer-events-auto h-auto max-h-[45vh] md:max-h-full overflow-y-auto mb-4 md:mb-0">
53
+ <h1 class="text-3xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-orange-400 to-yellow-200 mb-2">Rahu & Ketu</h1>
54
+ <h2 class="text-sm text-gray-300 uppercase tracking-widest mb-6 border-b border-gray-600 pb-2">The Lunar Nodes</h2>
55
+
56
+ <div class="space-y-4 text-sm leading-relaxed text-gray-200">
57
+ <p>
58
+ <strong class="text-white text-base">What are they?</strong><br>
59
+ In astronomy, Rahu and Ketu are not physical planets. They are mathematical intersection points known as the <strong>Lunar Nodes</strong>.
60
+ </p>
61
+ <p>
62
+ The Earth orbits the Sun on a flat plane called the <em>Ecliptic</em>. However, the Moon's orbit around the Earth is tilted by about 5 degrees relative to this plane.
63
+ </p>
64
+ <p>
65
+ Because of this tilt, the Moon's orbit crosses the Earth's Ecliptic plane at exactly two points.
66
+ </p>
67
+
68
+ <div class="bg-orange-500/10 border border-orange-500/30 p-3 rounded-lg mt-2">
69
+ <h3 class="text-orange-400 font-bold mb-1">Rahu (North Node) ☊</h3>
70
+ <p class="text-xs">The <em>Ascending Node</em>. This is the exact point where the Moon crosses the ecliptic going from South to North.</p>
71
+ </div>
72
+
73
+ <div class="bg-gray-500/10 border border-gray-500/30 p-3 rounded-lg mt-2">
74
+ <h3 class="text-gray-300 font-bold mb-1">Ketu (South Node) ☋</h3>
75
+ <p class="text-xs">The <em>Descending Node</em>. This is the exact point where the Moon crosses the ecliptic going from North to South.</p>
76
+ </div>
77
+
78
+ <div class="bg-purple-500/10 border border-purple-500/30 p-3 rounded-lg mt-2">
79
+ <h3 class="text-purple-400 font-bold mb-1">The 18.6 Year Cycle</h3>
80
+ <p class="text-xs">The nodes are not stationary! The Moon's orbital plane slowly wobbles, causing the nodes to drift backwards (retrograde). It takes exactly <strong>18.6 years</strong> for Rahu and Ketu to complete one full cycle around the Zodiac. This is called <em>Nodal Precession</em>.</p>
81
+ </div>
82
+
83
+ <p class="mt-4 border-t border-gray-600 pt-4">
84
+ <strong class="text-yellow-300">Eclipses:</strong> A Solar or Lunar eclipse can <em>only</em> happen when the New Moon or Full Moon aligns closely with either Rahu or Ketu. In ancient mythology, these nodes were personified as shadow demons that "swallowed" the Sun and Moon.
85
+ </p>
86
+ </div>
87
+ </div>
88
+
89
+ <!-- Right / Bottom Controls -->
90
+ <div class="flex flex-col justify-end pointer-events-auto w-full md:w-auto">
91
+ <div class="glass-panel rounded-2xl p-5 w-full md:w-80 space-y-5">
92
+
93
+ <div class="flex items-center justify-between mb-2">
94
+ <h3 class="font-semibold text-white">Controls</h3>
95
+ <button id="btn-pause" class="bg-white/10 hover:bg-white/20 text-white px-3 py-1 rounded text-sm transition">Pause</button>
96
+ </div>
97
+
98
+ <!-- Time Speed -->
99
+ <div>
100
+ <label class="flex justify-between text-xs text-gray-400 mb-2">
101
+ <span>Time Speed</span>
102
+ <span id="speed-val">1x</span>
103
+ </label>
104
+ <input type="range" id="time-speed" min="0" max="5" step="0.1" value="1" class="w-full">
105
+ </div>
106
+
107
+ <!-- Camera Focus -->
108
+ <div>
109
+ <label class="block text-xs text-gray-400 mb-2">Camera Focus</label>
110
+ <div class="flex bg-black/40 rounded-lg p-1">
111
+ <button id="focus-sun" class="flex-1 py-1.5 text-sm rounded-md transition text-gray-400 hover:text-white">Sun</button>
112
+ <button id="focus-earth" class="flex-1 py-1.5 text-sm rounded-md transition bg-blue-500/30 text-blue-200 border border-blue-500/50">Earth</button>
113
+ </div>
114
+ </div>
115
+
116
+ <!-- Visibility Toggles -->
117
+ <div class="pt-2 border-t border-gray-700/50 space-y-2">
118
+ <div class="mb-3">
119
+ <label class="block text-xs text-gray-400 mb-1">Show Nodes</label>
120
+ <select id="node-display-mode" class="w-full bg-gray-800 text-white text-sm rounded border border-gray-600 p-1.5 focus:ring-blue-500 focus:outline-none">
121
+ <option value="always">Always Show</option>
122
+ <option value="intersect">Only on Intersection</option>
123
+ </select>
124
+ </div>
125
+
126
+ <label class="flex items-center space-x-2 text-sm cursor-pointer">
127
+ <input type="checkbox" id="toggle-ecliptic" checked class="rounded bg-gray-800 border-gray-600 text-blue-500 focus:ring-blue-500">
128
+ <span class="text-gray-300">Show Earth's Plane (Ecliptic)</span>
129
+ </label>
130
+ <label class="flex items-center space-x-2 text-sm cursor-pointer">
131
+ <input type="checkbox" id="toggle-lunar" checked class="rounded bg-gray-800 border-gray-600 text-blue-500 focus:ring-blue-500">
132
+ <span class="text-gray-300">Show Moon's Tilted Plane</span>
133
+ </label>
134
+ </div>
135
+
136
+ <!-- Wobble Controls -->
137
+ <div class="pt-2 border-t border-gray-700/50 space-y-3">
138
+ <h4 class="text-xs font-semibold text-purple-400 uppercase tracking-wider">Lunar Wobble Controls</h4>
139
+
140
+ <div>
141
+ <label class="flex justify-between text-xs text-gray-400 mb-1">
142
+ <span>Wobble (Precession) Speed</span>
143
+ <span id="wobble-speed-val">1x</span>
144
+ </label>
145
+ <input type="range" id="wobble-speed" min="0" max="100" step="1" value="1" class="w-full">
146
+ </div>
147
+
148
+ <div>
149
+ <label class="flex justify-between text-xs text-gray-400 mb-1">
150
+ <span>Tilt Angle</span>
151
+ <span id="tilt-val">15°</span>
152
+ </label>
153
+ <input type="range" id="tilt-angle" min="0" max="45" step="1" value="15" class="w-full">
154
+ </div>
155
+
156
+ <label class="flex items-center space-x-2 text-sm cursor-pointer">
157
+ <input type="checkbox" id="toggle-axis" checked class="rounded bg-gray-800 border-gray-600 text-purple-500 focus:ring-purple-500">
158
+ <span class="text-gray-300">Show Orbital Axis</span>
159
+ </label>
160
+ </div>
161
+
162
+ </div>
163
+ </div>
164
+ </div>
165
+
166
+ <script>
167
+ // --- THREE.JS SETUP ---
168
+ const canvasContainer = document.getElementById('canvas-container');
169
+ const scene = new THREE.Scene();
170
+
171
+ // Camera setup
172
+ const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 2000);
173
+ camera.position.set(0, 80, 150);
174
+
175
+ // Renderer setup
176
+ const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
177
+ renderer.setSize(window.innerWidth, window.innerHeight);
178
+ renderer.setPixelRatio(window.devicePixelRatio);
179
+ canvasContainer.appendChild(renderer.domElement);
180
+
181
+ // OrbitControls
182
+ const controls = new THREE.OrbitControls(camera, renderer.domElement);
183
+ controls.enableDamping = true;
184
+ controls.dampingFactor = 0.05;
185
+ controls.maxDistance = 600;
186
+ controls.minDistance = 20;
187
+
188
+ // --- ENVIRONMENT ---
189
+ // Starfield
190
+ const starsGeometry = new THREE.BufferGeometry();
191
+ const starsCount = 3000;
192
+ const posArray = new Float32Array(starsCount * 3);
193
+ for(let i = 0; i < starsCount * 3; i++) {
194
+ posArray[i] = (Math.random() - 0.5) * 1500;
195
+ }
196
+ starsGeometry.setAttribute('position', new THREE.BufferAttribute(posArray, 3));
197
+ const starsMaterial = new THREE.PointsMaterial({ size: 1.5, color: 0xffffff, transparent: true, opacity: 0.8 });
198
+ const starMesh = new THREE.Points(starsGeometry, starsMaterial);
199
+ scene.add(starMesh);
200
+
201
+ // Ambient Light
202
+ scene.add(new THREE.AmbientLight(0x333344));
203
+
204
+ // --- CELESTIAL BODIES ---
205
+
206
+ // 1. SUN SYSTEM
207
+ const sunSystem = new THREE.Group();
208
+ scene.add(sunSystem);
209
+
210
+ // Sun Mesh
211
+ const sunGeo = new THREE.SphereGeometry(15, 32, 32);
212
+ const sunMat = new THREE.MeshBasicMaterial({ color: 0xffaa00 });
213
+ const sun = new THREE.Mesh(sunGeo, sunMat);
214
+ sunSystem.add(sun);
215
+
216
+ // Sun Light
217
+ const sunLight = new THREE.PointLight(0xffffff, 2.5, 1000);
218
+ sunSystem.add(sunLight);
219
+
220
+ // Sun Glow (Sprite)
221
+ const glowCanvas = document.createElement('canvas');
222
+ glowCanvas.width = 128; glowCanvas.height = 128;
223
+ const ctx = glowCanvas.getContext('2d');
224
+ const gradient = ctx.createRadialGradient(64,64,0, 64,64,64);
225
+ gradient.addColorStop(0, 'rgba(255, 170, 0, 0.6)');
226
+ gradient.addColorStop(1, 'rgba(255, 170, 0, 0)');
227
+ ctx.fillStyle = gradient;
228
+ ctx.fillRect(0,0, 128,128);
229
+ const glowTexture = new THREE.CanvasTexture(glowCanvas);
230
+ const glowMaterial = new THREE.SpriteMaterial({ map: glowTexture, blending: THREE.AdditiveBlending, transparent: true });
231
+ const sunGlow = new THREE.Sprite(glowMaterial);
232
+ sunGlow.scale.set(60, 60, 1);
233
+ sun.add(sunGlow);
234
+
235
+ // 2. EARTH SYSTEM
236
+ const earthOrbitRadius = 120;
237
+ const earthSystem = new THREE.Group();
238
+ scene.add(earthSystem);
239
+
240
+ // Earth Orbit Line
241
+ const earthOrbitGeo = new THREE.RingGeometry(earthOrbitRadius - 0.2, earthOrbitRadius + 0.2, 128);
242
+ const earthOrbitMat = new THREE.MeshBasicMaterial({ color: 0x445566, side: THREE.DoubleSide, transparent: true, opacity: 0.5 });
243
+ const earthOrbitLine = new THREE.Mesh(earthOrbitGeo, earthOrbitMat);
244
+ earthOrbitLine.rotation.x = Math.PI / 2;
245
+ scene.add(earthOrbitLine);
246
+
247
+ // Earth Mesh
248
+ const earthGeo = new THREE.SphereGeometry(4, 32, 32);
249
+ const earthMat = new THREE.MeshStandardMaterial({ color: 0x2288ff, roughness: 0.6 });
250
+ const earth = new THREE.Mesh(earthGeo, earthMat);
251
+ earthSystem.add(earth);
252
+
253
+ // Ecliptic Plane (Local to Earth)
254
+ const eclipticGeo = new THREE.PlaneGeometry(60, 60);
255
+ const eclipticMat = new THREE.MeshBasicMaterial({ color: 0x22ff44, transparent: true, opacity: 0.1, side: THREE.DoubleSide });
256
+ const eclipticPlane = new THREE.Mesh(eclipticGeo, eclipticMat);
257
+ eclipticPlane.rotation.x = Math.PI / 2;
258
+ earthSystem.add(eclipticPlane);
259
+
260
+ // Ecliptic Grid Helper to make it clearer
261
+ const eclipticGrid = new THREE.GridHelper(60, 10, 0x22ff44, 0x22ff44);
262
+ eclipticGrid.material.opacity = 0.2;
263
+ eclipticGrid.material.transparent = true;
264
+ earthSystem.add(eclipticGrid);
265
+
266
+ // 3. MOON SYSTEM & NODAL PRECESSION
267
+ const nodalPrecessionGroup = new THREE.Group();
268
+ earthSystem.add(nodalPrecessionGroup);
269
+
270
+ const moonOrbitRadius = 22;
271
+ const moonSystem = new THREE.Group();
272
+
273
+ // TILT THE LUNAR ORBIT (Exaggerated to 15 degrees for visual clarity, real is ~5 degrees)
274
+ let lunarTilt = 15 * (Math.PI / 180);
275
+ moonSystem.rotation.x = lunarTilt;
276
+ nodalPrecessionGroup.add(moonSystem);
277
+
278
+ // Moon Orbit Axis (To visualize the wobble)
279
+ const axisGeo = new THREE.BufferGeometry().setFromPoints([
280
+ new THREE.Vector3(0, -30, 0),
281
+ new THREE.Vector3(0, 30, 0)
282
+ ]);
283
+ const axisMat = new THREE.LineBasicMaterial({ color: 0xdd44ff, transparent: true, opacity: 0.8, linewidth: 2 });
284
+ const moonOrbitAxis = new THREE.Line(axisGeo, axisMat);
285
+ moonSystem.add(moonOrbitAxis);
286
+
287
+ // Moon Plane
288
+ const lunarPlaneGeo = new THREE.PlaneGeometry(50, 50);
289
+ const lunarPlaneMat = new THREE.MeshBasicMaterial({ color: 0x44aaff, transparent: true, opacity: 0.15, side: THREE.DoubleSide });
290
+ const lunarPlane = new THREE.Mesh(lunarPlaneGeo, lunarPlaneMat);
291
+ lunarPlane.rotation.x = Math.PI / 2;
292
+ moonSystem.add(lunarPlane);
293
+
294
+ // Moon Orbit Line
295
+ const moonOrbitLineGeo = new THREE.RingGeometry(moonOrbitRadius - 0.2, moonOrbitRadius + 0.2, 64);
296
+ const moonOrbitLineMat = new THREE.MeshBasicMaterial({ color: 0xaaaaff, side: THREE.DoubleSide, transparent: true, opacity: 0.8 });
297
+ const moonOrbitLine = new THREE.Mesh(moonOrbitLineGeo, moonOrbitLineMat);
298
+ moonOrbitLine.rotation.x = Math.PI / 2;
299
+ moonSystem.add(moonOrbitLine);
300
+
301
+ // Moon Mesh
302
+ const moonGeo = new THREE.SphereGeometry(1.2, 16, 16);
303
+ const moonMat = new THREE.MeshStandardMaterial({ color: 0xdddddd, roughness: 0.8 });
304
+ const moon = new THREE.Mesh(moonGeo, moonMat);
305
+ moonSystem.add(moon);
306
+
307
+ // --- RAHU & KETU NODES ---
308
+ // Create Sprite Text Labels
309
+ function createTextLabel(text, color) {
310
+ const canvas = document.createElement('canvas');
311
+ canvas.width = 512; canvas.height = 128;
312
+ const ctx = canvas.getContext('2d');
313
+ ctx.fillStyle = color;
314
+ ctx.font = 'bold 36px sans-serif';
315
+ ctx.textAlign = 'center';
316
+ ctx.textBaseline = 'middle';
317
+
318
+ // Background capsule
319
+ ctx.fillStyle = 'rgba(0, 0, 0, 0.6)';
320
+ ctx.beginPath();
321
+ ctx.roundRect(64, 20, 384, 88, 44);
322
+ ctx.fill();
323
+ ctx.strokeStyle = color;
324
+ ctx.lineWidth = 3;
325
+ ctx.stroke();
326
+
327
+ // Text
328
+ ctx.fillStyle = color;
329
+ ctx.fillText(text, 256, 64);
330
+
331
+ const texture = new THREE.CanvasTexture(canvas);
332
+ const material = new THREE.SpriteMaterial({ map: texture, depthTest: false });
333
+ const sprite = new THREE.Sprite(material);
334
+ sprite.scale.set(16, 4, 1);
335
+ return sprite;
336
+ }
337
+
338
+ function createNodeMarker(color) {
339
+ const geo = new THREE.SphereGeometry(1.5, 16, 16);
340
+ const mat = new THREE.MeshBasicMaterial({ color: color });
341
+ return new THREE.Mesh(geo, mat);
342
+ }
343
+
344
+ // The intersection of the tilted Moon system with the Ecliptic (Earth's XZ plane) happens along the local X-axis.
345
+ // Because we rotated the moonSystem around X, the X-axis remains unchanged and perfectly lies on the Ecliptic.
346
+ // Rahu (Ascending Node) - Going South to North. Due to rotation rules, this occurs at -X.
347
+ const rahuLabel = createTextLabel("Rahu ☊", "#ff8800");
348
+ rahuLabel.position.set(-moonOrbitRadius, 5, 0);
349
+ const rahuMarker = createNodeMarker(0xff8800);
350
+ rahuMarker.position.set(-moonOrbitRadius, 0, 0);
351
+ moonSystem.add(rahuLabel);
352
+ moonSystem.add(rahuMarker);
353
+
354
+ // Ketu (Descending Node) - Going North to South. This occurs at +X.
355
+ const ketuLabel = createTextLabel("Ketu ☋", "#a0a0a0");
356
+ ketuLabel.position.set(moonOrbitRadius, 5, 0);
357
+ const ketuMarker = createNodeMarker(0xa0a0a0);
358
+ ketuMarker.position.set(moonOrbitRadius, 0, 0);
359
+ moonSystem.add(ketuLabel);
360
+ moonSystem.add(ketuMarker);
361
+
362
+ // Line of Nodes
363
+ const lineOfNodesGeo = new THREE.BufferGeometry().setFromPoints([
364
+ new THREE.Vector3(-moonOrbitRadius - 5, 0, 0),
365
+ new THREE.Vector3(moonOrbitRadius + 5, 0, 0)
366
+ ]);
367
+ const lineOfNodesMat = new THREE.LineBasicMaterial({ color: 0xffffff, transparent: true, opacity: 0.7 });
368
+ const lineOfNodes = new THREE.Line(lineOfNodesGeo, lineOfNodesMat);
369
+ moonSystem.add(lineOfNodes);
370
+
371
+ // --- ANIMATION LOGIC ---
372
+ let time = 0;
373
+ let wobbleTime = 0; // Separate time tracker for wobble
374
+ let isPaused = false;
375
+ let speedMultiplier = 1;
376
+ let wobbleSpeedMultiplier = 1; // Default independent wobble speed
377
+ let currentTilt = 15; // Default tilt in degrees
378
+ let cameraFocus = 'earth'; // 'earth' or 'sun'
379
+ let nodeDisplayMode = 'always'; // 'always' or 'intersect'
380
+ const earthWorldPos = new THREE.Vector3();
381
+
382
+ // Set initial camera to Earth
383
+ camera.position.set(170, 40, 60);
384
+
385
+ function animate() {
386
+ requestAnimationFrame(animate);
387
+
388
+ if (!isPaused) {
389
+ time += 0.005 * speedMultiplier;
390
+ wobbleTime += 0.005 * speedMultiplier * wobbleSpeedMultiplier;
391
+
392
+ // Earth revolution around Sun (1 Earth Year)
393
+ earthSystem.position.x = Math.cos(time) * earthOrbitRadius;
394
+ earthSystem.position.z = Math.sin(time) * earthOrbitRadius;
395
+
396
+ // Earth rotation
397
+ earth.rotation.y += 0.05 * speedMultiplier;
398
+
399
+ // Nodal Precession (Takes 18.6 Earth Years, moves Retrograde/Backwards)
400
+ // We divide time by 18.6 so it takes exactly 18.6 Earth revolutions to do 1 Node revolution
401
+ nodalPrecessionGroup.rotation.y = -(wobbleTime / 18.6);
402
+
403
+ // Update Lunar Tilt Dynamically
404
+ moonSystem.rotation.x = currentTilt * (Math.PI / 180);
405
+
406
+ // Moon revolution around Earth
407
+ // Inside moonSystem, rotation around Y moves it along the tilted orbit!
408
+ const moonSpeed = time * 13.36; // Moon revolves ~13.36 times a year
409
+ moon.position.x = Math.cos(moonSpeed) * moonOrbitRadius;
410
+ moon.position.z = Math.sin(moonSpeed) * moonOrbitRadius;
411
+ moon.rotation.y += 0.02 * speedMultiplier;
412
+
413
+ // Handle Node Visibility Mode
414
+ if (nodeDisplayMode === 'intersect') {
415
+ // Calculate moon's current angle to determine proximity to nodes (0 and PI)
416
+ let moonAngle = moonSpeed % (Math.PI * 2);
417
+ if (moonAngle < 0) moonAngle += Math.PI * 2;
418
+
419
+ const threshold = 0.35; // Visibility window in radians (~20 degrees)
420
+ const isNearKetu = (moonAngle < threshold) || (moonAngle > Math.PI * 2 - threshold); // Ketu is at 0 / 2PI (+X)
421
+ const isNearRahu = Math.abs(moonAngle - Math.PI) < threshold; // Rahu is at PI (-X)
422
+
423
+ rahuLabel.visible = isNearRahu;
424
+ rahuMarker.visible = isNearRahu;
425
+ ketuLabel.visible = isNearKetu;
426
+ ketuMarker.visible = isNearKetu;
427
+ }
428
+
429
+ // Make text sprites always face camera
430
+ rahuLabel.material.rotation = 0;
431
+ ketuLabel.material.rotation = 0;
432
+ }
433
+
434
+ // Camera Tracking
435
+ earthSystem.getWorldPosition(earthWorldPos);
436
+
437
+ if (cameraFocus === 'earth') {
438
+ controls.target.copy(earthWorldPos);
439
+ } else {
440
+ controls.target.set(0, 0, 0);
441
+ }
442
+
443
+ controls.update();
444
+ renderer.render(scene, camera);
445
+ }
446
+
447
+ // --- UI INTERACTIONS ---
448
+
449
+ // Pause Button
450
+ const btnPause = document.getElementById('btn-pause');
451
+ btnPause.addEventListener('click', () => {
452
+ isPaused = !isPaused;
453
+ btnPause.innerText = isPaused ? "Play" : "Pause";
454
+ btnPause.className = isPaused
455
+ ? "bg-green-500 hover:bg-green-600 text-white px-3 py-1 rounded text-sm transition"
456
+ : "bg-white/10 hover:bg-white/20 text-white px-3 py-1 rounded text-sm transition";
457
+ });
458
+
459
+ // Speed Slider
460
+ const speedSlider = document.getElementById('time-speed');
461
+ const speedVal = document.getElementById('speed-val');
462
+ speedSlider.addEventListener('input', (e) => {
463
+ speedMultiplier = parseFloat(e.target.value);
464
+ speedVal.innerText = speedMultiplier.toFixed(1) + "x";
465
+ });
466
+
467
+ // Camera Focus Toggles
468
+ const btnFocusSun = document.getElementById('focus-sun');
469
+ const btnFocusEarth = document.getElementById('focus-earth');
470
+
471
+ btnFocusSun.addEventListener('click', () => {
472
+ cameraFocus = 'sun';
473
+ btnFocusSun.className = "flex-1 py-1.5 text-sm rounded-md transition bg-blue-500/30 text-blue-200 border border-blue-500/50";
474
+ btnFocusEarth.className = "flex-1 py-1.5 text-sm rounded-md transition text-gray-400 hover:text-white border border-transparent";
475
+
476
+ // Move camera to see whole system
477
+ const targetPos = new THREE.Vector3(0, 200, 300);
478
+ camera.position.lerp(targetPos, 1);
479
+ });
480
+
481
+ btnFocusEarth.addEventListener('click', () => {
482
+ cameraFocus = 'earth';
483
+ btnFocusEarth.className = "flex-1 py-1.5 text-sm rounded-md transition bg-blue-500/30 text-blue-200 border border-blue-500/50";
484
+ btnFocusSun.className = "flex-1 py-1.5 text-sm rounded-md transition text-gray-400 hover:text-white border border-transparent";
485
+
486
+ // Move camera closer to earth
487
+ earthSystem.getWorldPosition(earthWorldPos);
488
+ camera.position.set(earthWorldPos.x, earthWorldPos.y + 40, earthWorldPos.z + 60);
489
+ });
490
+
491
+ // Visibility Toggles
492
+ document.getElementById('node-display-mode').addEventListener('change', (e) => {
493
+ nodeDisplayMode = e.target.value;
494
+ if (nodeDisplayMode === 'always') {
495
+ rahuLabel.visible = true;
496
+ rahuMarker.visible = true;
497
+ ketuLabel.visible = true;
498
+ ketuMarker.visible = true;
499
+ }
500
+ });
501
+
502
+ document.getElementById('toggle-ecliptic').addEventListener('change', (e) => {
503
+ eclipticPlane.visible = e.target.checked;
504
+ eclipticGrid.visible = e.target.checked;
505
+ });
506
+
507
+ document.getElementById('toggle-lunar').addEventListener('change', (e) => {
508
+ lunarPlane.visible = e.target.checked;
509
+ });
510
+
511
+ // Wobble Control Listeners
512
+ const wobbleSpeedSlider = document.getElementById('wobble-speed');
513
+ const wobbleSpeedVal = document.getElementById('wobble-speed-val');
514
+ wobbleSpeedSlider.addEventListener('input', (e) => {
515
+ wobbleSpeedMultiplier = parseFloat(e.target.value);
516
+ wobbleSpeedVal.innerText = wobbleSpeedMultiplier + "x";
517
+ });
518
+
519
+ const tiltSlider = document.getElementById('tilt-angle');
520
+ const tiltVal = document.getElementById('tilt-val');
521
+ tiltSlider.addEventListener('input', (e) => {
522
+ currentTilt = parseFloat(e.target.value);
523
+ tiltVal.innerText = currentTilt + "°";
524
+ });
525
+
526
+ document.getElementById('toggle-axis').addEventListener('change', (e) => {
527
+ moonOrbitAxis.visible = e.target.checked;
528
+ });
529
+
530
+ // Handle Window Resize
531
+ window.addEventListener('resize', () => {
532
+ camera.aspect = window.innerWidth / window.innerHeight;
533
+ camera.updateProjectionMatrix();
534
+ renderer.setSize(window.innerWidth, window.innerHeight);
535
+ });
536
+
537
+ // Start animation loop
538
+ animate();
539
+
540
+ </script>
541
+ </body>
542
+ </html>