trysem commited on
Commit
0718c4b
·
verified ·
1 Parent(s): 6213d4f

Create rahuketu6

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