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

Create rahuketu4

Browse files
Files changed (1) hide show
  1. rahuketu4 +614 -0
rahuketu4 ADDED
@@ -0,0 +1,614 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <label class="flex items-center space-x-2 text-sm cursor-pointer">
135
+ <input type="checkbox" id="toggle-moon-orbit-line" checked class="rounded bg-gray-800 border-gray-600 text-blue-500 focus:ring-blue-500">
136
+ <span class="text-gray-300">Show Moon's Orbit Line</span>
137
+ </label>
138
+ </div>
139
+
140
+ <!-- Wobble Controls -->
141
+ <div class="pt-2 border-t border-gray-700/50 space-y-3">
142
+ <h4 class="text-xs font-semibold text-purple-400 uppercase tracking-wider">Lunar Wobble Controls</h4>
143
+
144
+ <div>
145
+ <label class="flex justify-between text-xs text-gray-400 mb-1">
146
+ <span>Wobble (Precession) Speed</span>
147
+ <span id="wobble-speed-val">1x</span>
148
+ </label>
149
+ <input type="range" id="wobble-speed" min="0" max="100" step="1" value="1" class="w-full">
150
+ </div>
151
+
152
+ <div>
153
+ <label class="flex justify-between text-xs text-gray-400 mb-1">
154
+ <span>Tilt Angle</span>
155
+ <span id="tilt-val">15°</span>
156
+ </label>
157
+ <input type="range" id="tilt-angle" min="0" max="45" step="1" value="15" class="w-full">
158
+ </div>
159
+
160
+ <label class="flex items-center space-x-2 text-sm cursor-pointer">
161
+ <input type="checkbox" id="toggle-axis" checked class="rounded bg-gray-800 border-gray-600 text-purple-500 focus:ring-purple-500">
162
+ <span class="text-gray-300">Show Orbital Axis</span>
163
+ </label>
164
+
165
+ <div class="mt-3 bg-purple-900/20 border border-purple-500/30 p-3 rounded-lg">
166
+ <label class="flex justify-between text-xs text-gray-400 mb-2">
167
+ <span class="flex items-center space-x-2">
168
+ <input type="checkbox" id="manual-precession-toggle" class="rounded bg-gray-800 border-gray-600 text-purple-500 focus:ring-purple-500">
169
+ <span class="text-purple-300 font-semibold">Manual 18.6 Yr Scrub</span>
170
+ </span>
171
+ <span id="precession-year-val" class="text-purple-300 font-mono">0.00 Yrs</span>
172
+ </label>
173
+ <input type="range" id="precession-slider" min="0" max="18.5996" step="0.01" value="0" class="w-full disabled:opacity-40 disabled:cursor-not-allowed" disabled>
174
+ </div>
175
+
176
+ <label class="flex items-center space-x-2 text-sm cursor-pointer border-t border-gray-700/50 pt-3">
177
+ <input type="checkbox" id="isolate-system" class="rounded bg-gray-800 border-gray-600 text-red-500 focus:ring-red-500">
178
+ <span class="text-gray-200 font-semibold">Isolate Earth & Moon</span>
179
+ </label>
180
+ </div>
181
+
182
+ </div>
183
+ </div>
184
+ </div>
185
+
186
+ <script>
187
+ // --- THREE.JS SETUP ---
188
+ const canvasContainer = document.getElementById('canvas-container');
189
+ const scene = new THREE.Scene();
190
+
191
+ // Camera setup
192
+ const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 2000);
193
+ camera.position.set(0, 80, 150);
194
+
195
+ // Renderer setup
196
+ const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
197
+ renderer.setSize(window.innerWidth, window.innerHeight);
198
+ renderer.setPixelRatio(window.devicePixelRatio);
199
+ canvasContainer.appendChild(renderer.domElement);
200
+
201
+ // OrbitControls
202
+ const controls = new THREE.OrbitControls(camera, renderer.domElement);
203
+ controls.enableDamping = true;
204
+ controls.dampingFactor = 0.05;
205
+ controls.maxDistance = 600;
206
+ controls.minDistance = 20;
207
+
208
+ // --- ENVIRONMENT ---
209
+ // Starfield
210
+ const starsGeometry = new THREE.BufferGeometry();
211
+ const starsCount = 3000;
212
+ const posArray = new Float32Array(starsCount * 3);
213
+ for(let i = 0; i < starsCount * 3; i++) {
214
+ posArray[i] = (Math.random() - 0.5) * 1500;
215
+ }
216
+ starsGeometry.setAttribute('position', new THREE.BufferAttribute(posArray, 3));
217
+ const starsMaterial = new THREE.PointsMaterial({ size: 1.5, color: 0xffffff, transparent: true, opacity: 0.8 });
218
+ const starMesh = new THREE.Points(starsGeometry, starsMaterial);
219
+ scene.add(starMesh);
220
+
221
+ // Ambient Light
222
+ scene.add(new THREE.AmbientLight(0x333344));
223
+
224
+ // --- CELESTIAL BODIES ---
225
+
226
+ // 1. SUN SYSTEM
227
+ const sunSystem = new THREE.Group();
228
+ scene.add(sunSystem);
229
+
230
+ // Sun Mesh
231
+ const sunGeo = new THREE.SphereGeometry(15, 32, 32);
232
+ const sunMat = new THREE.MeshBasicMaterial({ color: 0xffaa00 });
233
+ const sun = new THREE.Mesh(sunGeo, sunMat);
234
+ sunSystem.add(sun);
235
+
236
+ // Sun Light
237
+ const sunLight = new THREE.PointLight(0xffffff, 2.5, 1000);
238
+ sunSystem.add(sunLight);
239
+
240
+ // Sun Glow (Sprite)
241
+ const glowCanvas = document.createElement('canvas');
242
+ glowCanvas.width = 128; glowCanvas.height = 128;
243
+ const ctx = glowCanvas.getContext('2d');
244
+ const gradient = ctx.createRadialGradient(64,64,0, 64,64,64);
245
+ gradient.addColorStop(0, 'rgba(255, 170, 0, 0.6)');
246
+ gradient.addColorStop(1, 'rgba(255, 170, 0, 0)');
247
+ ctx.fillStyle = gradient;
248
+ ctx.fillRect(0,0, 128,128);
249
+ const glowTexture = new THREE.CanvasTexture(glowCanvas);
250
+ const glowMaterial = new THREE.SpriteMaterial({ map: glowTexture, blending: THREE.AdditiveBlending, transparent: true });
251
+ const sunGlow = new THREE.Sprite(glowMaterial);
252
+ sunGlow.scale.set(60, 60, 1);
253
+ sun.add(sunGlow);
254
+
255
+ // 2. EARTH SYSTEM
256
+ const earthOrbitRadius = 120;
257
+ const earthSystem = new THREE.Group();
258
+ scene.add(earthSystem);
259
+
260
+ // Earth Orbit Line
261
+ const earthOrbitGeo = new THREE.RingGeometry(earthOrbitRadius - 0.2, earthOrbitRadius + 0.2, 128);
262
+ const earthOrbitMat = new THREE.MeshBasicMaterial({ color: 0x445566, side: THREE.DoubleSide, transparent: true, opacity: 0.5 });
263
+ const earthOrbitLine = new THREE.Mesh(earthOrbitGeo, earthOrbitMat);
264
+ earthOrbitLine.rotation.x = Math.PI / 2;
265
+ scene.add(earthOrbitLine);
266
+
267
+ // Earth Mesh
268
+ const earthGeo = new THREE.SphereGeometry(4, 32, 32);
269
+ const earthMat = new THREE.MeshStandardMaterial({ color: 0x2288ff, roughness: 0.6 });
270
+ const earth = new THREE.Mesh(earthGeo, earthMat);
271
+ earthSystem.add(earth);
272
+
273
+ // Ecliptic Plane (Local to Earth)
274
+ const eclipticGeo = new THREE.PlaneGeometry(60, 60);
275
+ const eclipticMat = new THREE.MeshBasicMaterial({ color: 0x22ff44, transparent: true, opacity: 0.1, side: THREE.DoubleSide });
276
+ const eclipticPlane = new THREE.Mesh(eclipticGeo, eclipticMat);
277
+ eclipticPlane.rotation.x = Math.PI / 2;
278
+ earthSystem.add(eclipticPlane);
279
+
280
+ // Ecliptic Grid Helper to make it clearer
281
+ const eclipticGrid = new THREE.GridHelper(60, 10, 0x22ff44, 0x22ff44);
282
+ eclipticGrid.material.opacity = 0.2;
283
+ eclipticGrid.material.transparent = true;
284
+ earthSystem.add(eclipticGrid);
285
+
286
+ // 3. MOON SYSTEM & NODAL PRECESSION
287
+ const nodalPrecessionGroup = new THREE.Group();
288
+ earthSystem.add(nodalPrecessionGroup);
289
+
290
+ const moonOrbitRadius = 22;
291
+ const moonSystem = new THREE.Group();
292
+
293
+ // TILT THE LUNAR ORBIT (Exaggerated to 15 degrees for visual clarity, real is ~5 degrees)
294
+ let lunarTilt = 15 * (Math.PI / 180);
295
+ moonSystem.rotation.x = lunarTilt;
296
+ nodalPrecessionGroup.add(moonSystem);
297
+
298
+ // Moon Orbit Axis (To visualize the wobble)
299
+ const axisGeo = new THREE.BufferGeometry().setFromPoints([
300
+ new THREE.Vector3(0, -30, 0),
301
+ new THREE.Vector3(0, 30, 0)
302
+ ]);
303
+ const axisMat = new THREE.LineBasicMaterial({ color: 0xdd44ff, transparent: true, opacity: 0.8, linewidth: 2 });
304
+ const moonOrbitAxis = new THREE.Line(axisGeo, axisMat);
305
+ moonSystem.add(moonOrbitAxis);
306
+
307
+ // Moon Plane
308
+ const lunarPlaneGeo = new THREE.PlaneGeometry(50, 50);
309
+ const lunarPlaneMat = new THREE.MeshBasicMaterial({ color: 0x44aaff, transparent: true, opacity: 0.15, side: THREE.DoubleSide });
310
+ const lunarPlane = new THREE.Mesh(lunarPlaneGeo, lunarPlaneMat);
311
+ lunarPlane.rotation.x = Math.PI / 2;
312
+ moonSystem.add(lunarPlane);
313
+
314
+ // Moon Orbit Line
315
+ const moonOrbitLineGeo = new THREE.RingGeometry(moonOrbitRadius - 0.2, moonOrbitRadius + 0.2, 64);
316
+ const moonOrbitLineMat = new THREE.MeshBasicMaterial({ color: 0xaaaaff, side: THREE.DoubleSide, transparent: true, opacity: 0.8 });
317
+ const moonOrbitLine = new THREE.Mesh(moonOrbitLineGeo, moonOrbitLineMat);
318
+ moonOrbitLine.rotation.x = Math.PI / 2;
319
+ moonSystem.add(moonOrbitLine);
320
+
321
+ // Moon Mesh
322
+ const moonGeo = new THREE.SphereGeometry(1.2, 16, 16);
323
+ const moonMat = new THREE.MeshStandardMaterial({ color: 0xdddddd, roughness: 0.8 });
324
+ const moon = new THREE.Mesh(moonGeo, moonMat);
325
+ moonSystem.add(moon);
326
+
327
+ // --- RAHU & KETU NODES ---
328
+ // Create Sprite Text Labels
329
+ function createTextLabel(text, color) {
330
+ const canvas = document.createElement('canvas');
331
+ canvas.width = 512; canvas.height = 128;
332
+ const ctx = canvas.getContext('2d');
333
+ ctx.fillStyle = color;
334
+ ctx.font = 'bold 36px sans-serif';
335
+ ctx.textAlign = 'center';
336
+ ctx.textBaseline = 'middle';
337
+
338
+ // Background capsule
339
+ ctx.fillStyle = 'rgba(0, 0, 0, 0.6)';
340
+ ctx.beginPath();
341
+ ctx.roundRect(64, 20, 384, 88, 44);
342
+ ctx.fill();
343
+ ctx.strokeStyle = color;
344
+ ctx.lineWidth = 3;
345
+ ctx.stroke();
346
+
347
+ // Text
348
+ ctx.fillStyle = color;
349
+ ctx.fillText(text, 256, 64);
350
+
351
+ const texture = new THREE.CanvasTexture(canvas);
352
+ const material = new THREE.SpriteMaterial({ map: texture, depthTest: false });
353
+ const sprite = new THREE.Sprite(material);
354
+ sprite.scale.set(16, 4, 1);
355
+ return sprite;
356
+ }
357
+
358
+ function createNodeMarker(color) {
359
+ const geo = new THREE.SphereGeometry(1.5, 16, 16);
360
+ const mat = new THREE.MeshBasicMaterial({ color: color });
361
+ return new THREE.Mesh(geo, mat);
362
+ }
363
+
364
+ // The intersection of the tilted Moon system with the Ecliptic (Earth's XZ plane) happens along the local X-axis.
365
+ // Because we rotated the moonSystem around X, the X-axis remains unchanged and perfectly lies on the Ecliptic.
366
+ // Rahu (Ascending Node) - Going South to North. Due to rotation rules, this occurs at -X.
367
+ const rahuLabel = createTextLabel("Rahu ☊", "#ff8800");
368
+ rahuLabel.position.set(-moonOrbitRadius, 5, 0);
369
+ const rahuMarker = createNodeMarker(0xff8800);
370
+ rahuMarker.position.set(-moonOrbitRadius, 0, 0);
371
+ moonSystem.add(rahuLabel);
372
+ moonSystem.add(rahuMarker);
373
+
374
+ // Ketu (Descending Node) - Going North to South. This occurs at +X.
375
+ const ketuLabel = createTextLabel("Ketu ☋", "#a0a0a0");
376
+ ketuLabel.position.set(moonOrbitRadius, 5, 0);
377
+ const ketuMarker = createNodeMarker(0xa0a0a0);
378
+ ketuMarker.position.set(moonOrbitRadius, 0, 0);
379
+ moonSystem.add(ketuLabel);
380
+ moonSystem.add(ketuMarker);
381
+
382
+ // Line of Nodes
383
+ const lineOfNodesGeo = new THREE.BufferGeometry().setFromPoints([
384
+ new THREE.Vector3(-moonOrbitRadius - 5, 0, 0),
385
+ new THREE.Vector3(moonOrbitRadius + 5, 0, 0)
386
+ ]);
387
+ const lineOfNodesMat = new THREE.LineBasicMaterial({ color: 0xffffff, transparent: true, opacity: 0.7 });
388
+ const lineOfNodes = new THREE.Line(lineOfNodesGeo, lineOfNodesMat);
389
+ moonSystem.add(lineOfNodes);
390
+
391
+ // --- ANIMATION LOGIC ---
392
+ let time = 0;
393
+ let wobbleTime = 0; // Separate time tracker for wobble
394
+ let isPaused = false;
395
+ let speedMultiplier = 1;
396
+ let wobbleSpeedMultiplier = 1; // Default independent wobble speed
397
+ let currentTilt = 15; // Default tilt in degrees
398
+ let cameraFocus = 'earth'; // 'earth' or 'sun'
399
+ let nodeDisplayMode = 'always'; // 'always' or 'intersect'
400
+ const earthWorldPos = new THREE.Vector3();
401
+
402
+ // Set initial camera to Earth
403
+ camera.position.set(170, 40, 60);
404
+
405
+ function animate() {
406
+ requestAnimationFrame(animate);
407
+
408
+ const manualToggle = document.getElementById('manual-precession-toggle');
409
+ const precessionSlider = document.getElementById('precession-slider');
410
+ const precessionVal = document.getElementById('precession-year-val');
411
+ const exactPrecessionYears = 18.5996; // Cutting edge precise astronomical period
412
+
413
+ if (!isPaused) {
414
+ time += 0.005 * speedMultiplier;
415
+
416
+ if (!manualToggle.checked) {
417
+ wobbleTime += 0.005 * speedMultiplier * wobbleSpeedMultiplier;
418
+ }
419
+
420
+ // Earth revolution around Sun (1 Earth Year)
421
+ earthSystem.position.x = Math.cos(time) * earthOrbitRadius;
422
+ earthSystem.position.z = Math.sin(time) * earthOrbitRadius;
423
+
424
+ // Earth rotation
425
+ earth.rotation.y += 0.05 * speedMultiplier;
426
+
427
+ // Moon revolution around Earth
428
+ // Inside moonSystem, rotation around Y moves it along the tilted orbit!
429
+ const moonSpeed = time * 13.36; // Moon revolves ~13.36 times a year
430
+ moon.position.x = Math.cos(moonSpeed) * moonOrbitRadius;
431
+ moon.position.z = Math.sin(moonSpeed) * moonOrbitRadius;
432
+ moon.rotation.y += 0.02 * speedMultiplier;
433
+ }
434
+
435
+ // --- PRECESSION LOGIC (18.6 Year Cycle) ---
436
+ // Moved outside the !isPaused block so you can scrub while paused!
437
+ if (manualToggle.checked) {
438
+ // Manual Scrubbing
439
+ let manualYears = parseFloat(precessionSlider.value);
440
+ nodalPrecessionGroup.rotation.y = -(manualYears / exactPrecessionYears) * (Math.PI * 2);
441
+ precessionVal.innerText = manualYears.toFixed(2) + " Yrs";
442
+
443
+ // Sync internal time so it doesn't jump when resuming auto play
444
+ wobbleTime = manualYears * (Math.PI * 2);
445
+ } else {
446
+ // Auto Precession
447
+ nodalPrecessionGroup.rotation.y = -(wobbleTime / exactPrecessionYears);
448
+
449
+ // Sync slider visually
450
+ let baseWobbleYears = (wobbleTime / (Math.PI * 2));
451
+ let currentWobbleYears = baseWobbleYears % exactPrecessionYears;
452
+ if (currentWobbleYears < 0) currentWobbleYears += exactPrecessionYears;
453
+
454
+ precessionSlider.value = currentWobbleYears;
455
+ precessionVal.innerText = currentWobbleYears.toFixed(2) + " Yrs";
456
+ }
457
+
458
+ // Update Lunar Tilt Dynamically
459
+ moonSystem.rotation.x = currentTilt * (Math.PI / 180);
460
+
461
+ // Handle Node Visibility Mode (Moved outside so scrubbing reveals nodes even when paused)
462
+ const currentMoonSpeed = time * 13.36;
463
+ if (nodeDisplayMode === 'intersect') {
464
+ // Calculate moon's current angle to determine proximity to nodes (0 and PI)
465
+ let moonAngle = currentMoonSpeed % (Math.PI * 2);
466
+ if (moonAngle < 0) moonAngle += Math.PI * 2;
467
+
468
+ const threshold = 0.35; // Visibility window in radians (~20 degrees)
469
+ const isNearKetu = (moonAngle < threshold) || (moonAngle > Math.PI * 2 - threshold); // Ketu is at 0 / 2PI (+X)
470
+ const isNearRahu = Math.abs(moonAngle - Math.PI) < threshold; // Rahu is at PI (-X)
471
+
472
+ rahuLabel.visible = isNearRahu;
473
+ rahuMarker.visible = isNearRahu;
474
+ ketuLabel.visible = isNearKetu;
475
+ ketuMarker.visible = isNearKetu;
476
+ }
477
+
478
+ // Make text sprites always face camera
479
+ rahuLabel.material.rotation = 0;
480
+ ketuLabel.material.rotation = 0;
481
+
482
+ // Camera Tracking
483
+ earthSystem.getWorldPosition(earthWorldPos);
484
+
485
+ if (cameraFocus === 'earth') {
486
+ controls.target.copy(earthWorldPos);
487
+ } else {
488
+ controls.target.set(0, 0, 0);
489
+ }
490
+
491
+ controls.update();
492
+ renderer.render(scene, camera);
493
+ }
494
+
495
+ // --- UI INTERACTIONS ---
496
+
497
+ // Pause Button
498
+ const btnPause = document.getElementById('btn-pause');
499
+ btnPause.addEventListener('click', () => {
500
+ isPaused = !isPaused;
501
+ btnPause.innerText = isPaused ? "Play" : "Pause";
502
+ btnPause.className = isPaused
503
+ ? "bg-green-500 hover:bg-green-600 text-white px-3 py-1 rounded text-sm transition"
504
+ : "bg-white/10 hover:bg-white/20 text-white px-3 py-1 rounded text-sm transition";
505
+ });
506
+
507
+ // Speed Slider
508
+ const speedSlider = document.getElementById('time-speed');
509
+ const speedVal = document.getElementById('speed-val');
510
+ speedSlider.addEventListener('input', (e) => {
511
+ speedMultiplier = parseFloat(e.target.value);
512
+ speedVal.innerText = speedMultiplier.toFixed(1) + "x";
513
+ });
514
+
515
+ // Camera Focus Toggles
516
+ const btnFocusSun = document.getElementById('focus-sun');
517
+ const btnFocusEarth = document.getElementById('focus-earth');
518
+
519
+ btnFocusSun.addEventListener('click', () => {
520
+ cameraFocus = 'sun';
521
+ btnFocusSun.className = "flex-1 py-1.5 text-sm rounded-md transition bg-blue-500/30 text-blue-200 border border-blue-500/50";
522
+ btnFocusEarth.className = "flex-1 py-1.5 text-sm rounded-md transition text-gray-400 hover:text-white border border-transparent";
523
+
524
+ // Move camera to see whole system
525
+ const targetPos = new THREE.Vector3(0, 200, 300);
526
+ camera.position.lerp(targetPos, 1);
527
+ });
528
+
529
+ btnFocusEarth.addEventListener('click', () => {
530
+ cameraFocus = 'earth';
531
+ btnFocusEarth.className = "flex-1 py-1.5 text-sm rounded-md transition bg-blue-500/30 text-blue-200 border border-blue-500/50";
532
+ btnFocusSun.className = "flex-1 py-1.5 text-sm rounded-md transition text-gray-400 hover:text-white border border-transparent";
533
+
534
+ // Move camera closer to earth
535
+ earthSystem.getWorldPosition(earthWorldPos);
536
+ camera.position.set(earthWorldPos.x, earthWorldPos.y + 40, earthWorldPos.z + 60);
537
+ });
538
+
539
+ // Visibility Toggles
540
+ document.getElementById('node-display-mode').addEventListener('change', (e) => {
541
+ nodeDisplayMode = e.target.value;
542
+ if (nodeDisplayMode === 'always') {
543
+ rahuLabel.visible = true;
544
+ rahuMarker.visible = true;
545
+ ketuLabel.visible = true;
546
+ ketuMarker.visible = true;
547
+ }
548
+ });
549
+
550
+ document.getElementById('toggle-ecliptic').addEventListener('change', (e) => {
551
+ eclipticPlane.visible = e.target.checked;
552
+ eclipticGrid.visible = e.target.checked;
553
+ });
554
+
555
+ document.getElementById('toggle-lunar').addEventListener('change', (e) => {
556
+ lunarPlane.visible = e.target.checked;
557
+ });
558
+
559
+ document.getElementById('toggle-moon-orbit-line').addEventListener('change', (e) => {
560
+ moonOrbitLine.visible = e.target.checked;
561
+ });
562
+
563
+ // Wobble Control Listeners
564
+ const wobbleSpeedSlider = document.getElementById('wobble-speed');
565
+ const wobbleSpeedVal = document.getElementById('wobble-speed-val');
566
+ wobbleSpeedSlider.addEventListener('input', (e) => {
567
+ wobbleSpeedMultiplier = parseFloat(e.target.value);
568
+ wobbleSpeedVal.innerText = wobbleSpeedMultiplier + "x";
569
+ });
570
+
571
+ const tiltSlider = document.getElementById('tilt-angle');
572
+ const tiltVal = document.getElementById('tilt-val');
573
+ tiltSlider.addEventListener('input', (e) => {
574
+ currentTilt = parseFloat(e.target.value);
575
+ tiltVal.innerText = currentTilt + "°";
576
+ });
577
+
578
+ document.getElementById('toggle-axis').addEventListener('change', (e) => {
579
+ moonOrbitAxis.visible = e.target.checked;
580
+ });
581
+
582
+ // Manual Precession Scrub Toggle
583
+ document.getElementById('manual-precession-toggle').addEventListener('change', (e) => {
584
+ document.getElementById('precession-slider').disabled = !e.target.checked;
585
+ });
586
+
587
+ // Isolate System Toggle
588
+ document.getElementById('isolate-system').addEventListener('change', (e) => {
589
+ const isIsolated = e.target.checked;
590
+ sun.visible = !isIsolated;
591
+ sunGlow.visible = !isIsolated;
592
+ earthOrbitLine.visible = !isIsolated;
593
+
594
+ if (isIsolated) {
595
+ // Force camera focus to Earth
596
+ cameraFocus = 'earth';
597
+ document.getElementById('focus-earth').className = "flex-1 py-1.5 text-sm rounded-md transition bg-blue-500/30 text-blue-200 border border-blue-500/50";
598
+ document.getElementById('focus-sun').className = "flex-1 py-1.5 text-sm rounded-md transition text-gray-400 hover:text-white border border-transparent";
599
+ }
600
+ });
601
+
602
+ // Handle Window Resize
603
+ window.addEventListener('resize', () => {
604
+ camera.aspect = window.innerWidth / window.innerHeight;
605
+ camera.updateProjectionMatrix();
606
+ renderer.setSize(window.innerWidth, window.innerHeight);
607
+ });
608
+
609
+ // Start animation loop
610
+ animate();
611
+
612
+ </script>
613
+ </body>
614
+ </html>