File size: 17,473 Bytes
426919c | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Andromeda Galaxy in 3D</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
background: linear-gradient(to bottom, #000428, #004e92);
color: white;
font-family: 'Arial', sans-serif;
}
canvas {
display: block;
}
.galaxy-info {
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(5px);
border-radius: 15px;
transition: all 0.3s ease;
}
.galaxy-info:hover {
background: rgba(0, 0, 0, 0.9);
}
.controls {
background: rgba(0, 0, 0, 0.5);
border-radius: 10px;
padding: 10px;
}
.star {
position: absolute;
background: white;
border-radius: 50%;
animation: twinkle var(--duration) infinite ease-in-out;
}
@keyframes twinkle {
0%, 100% { opacity: 0.2; }
50% { opacity: 1; }
}
</style>
</head>
<body class="relative h-screen flex flex-col">
<!-- Background stars -->
<div id="stars-container" class="absolute inset-0 overflow-hidden"></div>
<!-- Header -->
<header class="z-10 py-4 px-6 text-center">
<h1 class="text-4xl md:text-5xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-purple-400 to-blue-500">
Andromeda Galaxy in 3D
</h1>
<p class="mt-2 text-lg text-blue-200">M31 - Our Galactic Neighbor</p>
</header>
<!-- Main content -->
<main class="flex-grow flex flex-col md:flex-row items-center justify-center p-4 z-10">
<!-- 3D Galaxy Container -->
<div id="galaxy-container" class="w-full md:w-2/3 h-96 md:h-full relative">
<!-- This will be populated by Three.js -->
</div>
<!-- Galaxy Information -->
<div class="galaxy-info w-full md:w-1/3 p-6 mt-4 md:mt-0 md:ml-6">
<h2 class="text-2xl font-bold mb-4 text-purple-300">About Andromeda</h2>
<ul class="space-y-3">
<li><span class="font-semibold text-blue-300">Distance:</span> ~2.5 million light-years</li>
<li><span class="font-semibold text-blue-300">Diameter:</span> ~220,000 light-years</li>
<li><span class="font-semibold text-blue-300">Stars:</span> ~1 trillion (10<sup>12</sup>)</li>
<li><span class="font-semibold text-blue-300">Type:</span> Barred spiral galaxy</li>
<li><span class="font-semibold text-blue-300">Discovery:</span> 964 AD by Persian astronomer</li>
</ul>
<div class="mt-6 controls">
<div class="flex items-center mb-3">
<label for="rotation-speed" class="mr-3">Rotation Speed:</label>
<input type="range" id="rotation-speed" min="0" max="0.02" step="0.001" value="0.005" class="flex-grow">
</div>
<div class="flex items-center mb-3">
<label for="zoom" class="mr-3">Zoom:</label>
<input type="range" id="zoom" min="3" max="20" step="0.5" value="10" class="flex-grow">
</div>
<div class="flex items-center mb-3">
<label for="view-angle" class="mr-3">View Angle:</label>
<input type="range" id="view-angle" min="0" max="90" step="1" value="0" class="flex-grow">
</div>
<div class="flex space-x-2 mb-3">
<button id="frontal-view" class="px-3 py-1 bg-blue-600 hover:bg-blue-700 rounded transition flex-1">
Frontal
</button>
<button id="sagittal-view" class="px-3 py-1 bg-blue-600 hover:bg-blue-700 rounded transition flex-1">
Sagittal
</button>
<button id="top-view" class="px-3 py-1 bg-blue-600 hover:bg-blue-700 rounded transition flex-1">
Top
</button>
</div>
<button id="reset-view" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded transition w-full mb-3">
Reset View
</button>
<button id="add-stars" class="px-4 py-2 bg-purple-600 hover:bg-purple-700 rounded transition w-full">
Add More Stars
</button>
</div>
</div>
</main>
<!-- Footer -->
<footer class="z-10 py-3 text-center text-sm text-blue-300">
<p>Explore the beauty of our cosmic neighbor - The Andromeda Galaxy (M31)</p>
</footer>
<script>
// Create background stars
function createStars() {
const container = document.getElementById('stars-container');
const starCount = 200;
for (let i = 0; i < starCount; i++) {
const star = document.createElement('div');
star.className = 'star';
// Random properties
const size = Math.random() * 3;
const x = Math.random() * 100;
const y = Math.random() * 100;
const duration = 2 + Math.random() * 3;
star.style.width = `${size}px`;
star.style.height = `${size}px`;
star.style.left = `${x}%`;
star.style.top = `${y}%`;
star.style.setProperty('--duration', `${duration}s`);
container.appendChild(star);
}
}
// Initialize Three.js scene
function initGalaxy() {
const container = document.getElementById('galaxy-container');
// Scene
const scene = new THREE.Scene();
// Camera
const camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
camera.position.z = 15;
// Renderer
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(container.clientWidth, container.clientHeight);
container.appendChild(renderer.domElement);
// Create galaxy particles
const particleCount = 5000;
const particles = new THREE.BufferGeometry();
const positions = new Float32Array(particleCount * 3);
const colors = new Float32Array(particleCount * 3);
const color = new THREE.Color();
// Spiral galaxy parameters
const arms = 2;
const armSeparation = Math.PI * 2 / arms;
const coreRadius = 2;
const armWidth = 0.5;
for (let i = 0; i < particleCount; i++) {
// Spiral distribution
const arm = Math.floor(Math.random() * arms);
const angle = Math.random() * Math.PI * 2;
const radius = coreRadius + Math.random() * 5;
// Spiral shape
const spiralAngle = angle + arm * armSeparation;
const spiralRadius = radius * (1 + armWidth * Math.sin(angle * 5));
// Position
const x = spiralRadius * Math.cos(spiralAngle);
const y = spiralRadius * Math.sin(spiralAngle);
const z = (Math.random() - 0.5) * 0.5;
positions[i * 3] = x;
positions[i * 3 + 1] = y;
positions[i * 3 + 2] = z;
// Color - mix of blue, white and purple
const colorValue = Math.random();
if (colorValue < 0.7) {
color.setHSL(0.6, 0.75, 0.5 + Math.random() * 0.3); // Blue
} else if (colorValue < 0.9) {
color.setHSL(0.8, 0.8, 0.7); // Purple
} else {
color.setHSL(0, 0, 0.9 + Math.random() * 0.1); // White
}
colors[i * 3] = color.r;
colors[i * 3 + 1] = color.g;
colors[i * 3 + 2] = color.b;
}
particles.setAttribute('position', new THREE.BufferAttribute(positions, 3));
particles.setAttribute('color', new THREE.BufferAttribute(colors, 3));
// Particle material
const particleMaterial = new THREE.PointsMaterial({
size: 0.05,
vertexColors: true,
transparent: true,
opacity: 0.8,
sizeAttenuation: true
});
// Create galaxy particle system
const galaxy = new THREE.Points(particles, particleMaterial);
scene.add(galaxy);
// No lights needed since we're using MeshBasicMaterial
// Controls
const rotationSpeed = document.getElementById('rotation-speed');
const zoomControl = document.getElementById('zoom');
const viewAngleControl = document.getElementById('view-angle');
const frontalView = document.getElementById('frontal-view');
const sagittalView = document.getElementById('sagittal-view');
const topView = document.getElementById('top-view');
const resetView = document.getElementById('reset-view');
let currentRotationSpeed = parseFloat(rotationSpeed.value);
let targetZoom = parseFloat(zoomControl.value);
let targetRotationX = 0;
let targetRotationY = 0;
// Animation loop
function animate() {
requestAnimationFrame(animate);
// Get particle positions and update them for rotation
const positions = particles.attributes.position.array;
const particleCount = positions.length / 3;
for (let i = 0; i < particleCount; i++) {
const x = positions[i * 3];
const y = positions[i * 3 + 1];
// Calculate radius from center
const radius = Math.sqrt(x * x + y * y);
// Skip particles too close to center
if (radius < 0.5) continue;
// Calculate current angle
const angle = Math.atan2(y, x);
// Calculate rotation speed (faster near center)
const speed = currentRotationSpeed * (1 + (1 - radius/8));
// Update position with rotation
positions[i * 3] = radius * Math.cos(angle + speed);
positions[i * 3 + 1] = radius * Math.sin(angle + speed);
}
// Mark positions as needing update
particles.attributes.position.needsUpdate = true;
// Smooth zoom and rotation
camera.position.z += (targetZoom - camera.position.z) * 0.1;
galaxy.rotation.x += (targetRotationX - galaxy.rotation.x) * 0.1;
galaxy.rotation.y += (targetRotationY - galaxy.rotation.y) * 0.1;
renderer.render(scene, camera);
}
animate();
// Event listeners
rotationSpeed.addEventListener('input', () => {
currentRotationSpeed = parseFloat(rotationSpeed.value);
});
zoomControl.addEventListener('input', () => {
targetZoom = parseFloat(zoomControl.value);
});
// View angle control
viewAngleControl.addEventListener('input', () => {
const angle = parseFloat(viewAngleControl.value) * Math.PI / 180;
targetRotationX = angle;
});
// Preset views
frontalView.addEventListener('click', () => {
targetRotationX = 0;
targetRotationY = 0;
viewAngleControl.value = '0';
});
sagittalView.addEventListener('click', () => {
targetRotationX = Math.PI/2;
targetRotationY = 0;
viewAngleControl.value = '90';
});
topView.addEventListener('click', () => {
targetRotationX = 0;
targetRotationY = Math.PI/2;
viewAngleControl.value = '0';
});
resetView.addEventListener('click', () => {
rotationSpeed.value = '0.005';
currentRotationSpeed = 0.005;
zoomControl.value = '10';
targetZoom = 10;
targetRotationX = 0;
targetRotationY = 0;
viewAngleControl.value = '0';
galaxy.rotation.set(0, 0, 0);
});
// Add more stars button
const addStarsBtn = document.getElementById('add-stars');
addStarsBtn.addEventListener('click', () => {
const currentCount = particles.attributes.position.count;
const additionalStars = 1000; // Number of stars to add
const newCount = currentCount + additionalStars;
// Create new arrays with expanded size
const newPositions = new Float32Array(newCount * 3);
const newColors = new Float32Array(newCount * 3);
// Copy existing data
newPositions.set(particles.attributes.position.array);
newColors.set(particles.attributes.color.array);
// Add new stars
for (let i = currentCount; i < newCount; i++) {
// Same distribution logic as initial creation
const arm = Math.floor(Math.random() * arms);
const angle = Math.random() * Math.PI * 2;
const radius = coreRadius + Math.random() * 5;
const spiralAngle = angle + arm * armSeparation;
const spiralRadius = radius * (1 + armWidth * Math.sin(angle * 5));
newPositions[i * 3] = spiralRadius * Math.cos(spiralAngle);
newPositions[i * 3 + 1] = spiralRadius * Math.sin(spiralAngle);
newPositions[i * 3 + 2] = (Math.random() - 0.5) * 0.5;
// Color
const colorValue = Math.random();
if (colorValue < 0.7) {
color.setHSL(0.6, 0.75, 0.5 + Math.random() * 0.3);
} else if (colorValue < 0.9) {
color.setHSL(0.8, 0.8, 0.7);
} else {
color.setHSL(0, 0, 0.9 + Math.random() * 0.1);
}
newColors[i * 3] = color.r;
newColors[i * 3 + 1] = color.g;
newColors[i * 3 + 2] = color.b;
}
// Update geometry
particles.setAttribute('position', new THREE.BufferAttribute(newPositions, 3));
particles.setAttribute('color', new THREE.BufferAttribute(newColors, 3));
console.log(`Added ${additionalStars} stars. Total: ${newCount}`);
});
// Handle window resize
window.addEventListener('resize', () => {
camera.aspect = container.clientWidth / container.clientHeight;
camera.updateProjectionMatrix();
renderer.setSize(container.clientWidth, container.clientHeight);
});
}
// Initialize everything when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
createStars();
initGalaxy();
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Bohemicus/galaxy" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |