A continuación tienes un “mini-planetario” hecho sólo con HTML + JavaScript (Three.js).
• Cámara orbital con ratón / touch.
• Scroll para acercar/alejar.
• Deslizador para acelerar o frenar las órbitas.
• Código autocontenido, sin dependencias de build tools.
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Mini-Sistema Solar 3D</title>
<style>
html,body{margin:0;height:100%;overflow:hidden;background:#000;}
#speedUI{
position:fixed;left:10px;bottom:10px;padding:8px 14px;
background:rgba(0,0,0,.5);color:#fff;border-radius:8px;
font:14px/1 sans-serif;backdrop-filter:blur(4px);
}
#speedUI input{width:120px}
</style>
</head>
<body>
<div id="speedUI">Velocidad
<input id="speed" type="range" min="0" max="10" step="0.1" value="1">
<span id="speedVal">1×</span>
</div>
<script src="https://cdn.jsdelivr.net/npm/three@0.158/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.158/examples/js/controls/OrbitControls.js"></script>
<script>
/* --- 1. ESCENA BÁSICA --------------------------------------- */
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(60, innerWidth/innerHeight, 0.1, 2000);
camera.position.set(0, 120, 250);
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
/* --- 2. ILUMINACIÓN ----------------------------------------- */
const light = new THREE.PointLight(0xffffff, 2, 0);
light.position.set(0,0,0); // el Sol es la fuente
scene.add(light);
scene.add(new THREE.AmbientLight(0x222222));
/* --- 3. DATOS DE PLANETAS (todo muy… “a escala juguete”) ---- */
const AU = 50; // 1 UA (distancia Tierra–Sol) ==> 50 unidades 3D
const PLANETS = [
// name, radius(km), orbit radius AU, period días, color|texture
['Mercurio', 2440, 0.39, 88, 0x888888],
['Venus', 6050, 0.72, 225, 0xdaa520],
['Tierra', 6370, 1.00, 365, 'https://threejsfundamentals.org/threejs/resources/images/earth.jpg'],
['Marte', 3390, 1.52, 687, 0xb55332],
['Júpiter', 69900, 5.20, 4333, 0xd3a679],
['Saturno', 58200, 9.58, 10759,0xdeb887],
['Urano', 25300, 19.2, 30687,0x7fffd4],
['Neptuno', 24600, 30.1, 60190,0x4169e1],
];
/* --- escalamos radios (exageramos 2× para apreciarlos) -------- */
const Rscale = 0.0008*2;
/* --- 4. CREAR EL SOL ---------------------------------------- */
const sunGeo = new THREE.SphereGeometry(696000*Rscale, 32, 32);
const sunMat = new THREE.MeshBasicMaterial({color:0xffff00});
const sun = new THREE.Mesh(sunGeo, sunMat);
scene.add(sun);
/* --- 5. CREAR PLANETAS, cada uno dentro de un “pivot” -------- */
const pivots=[];
const loader = new THREE.TextureLoader();
PLANETS.forEach((p,i)=>{
const [name, radius, aAU, period, paint] = p;
const planetGeo = new THREE.SphereGeometry(radius*Rscale, 32, 32);
const mat = (typeof paint ==='string') ?
new THREE.MeshStandardMaterial({map: loader.load(paint)}) :
new THREE.MeshStandardMaterial({color:paint});
const mesh = new THREE.Mesh(planetGeo, mat);
mesh.position.set(aAU*AU,0,0); // sobre el eje X
mesh.userData = {period};
const pivot = new THREE.Object3D();
pivot.add(mesh);
scene.add(pivot);
pivots.push(pivot);
/* órbita visible (simple línea) */
const ring = new THREE.RingGeometry(aAU*AU-0.1, aAU*AU+0.1, 90);
const ringMat = new THREE.MeshBasicMaterial({color:0xffffff,side:THREE.DoubleSide});
const orbit = new THREE.Mesh(ring, ringMat);
orbit.rotation.x = Math.PI/2;
scene.add(orbit);
});
/* --- 6. UI: velocidad de simulación ------------------------- */
let timeScale = 1;
const speedSlider = document.getElementById('speed');
speedSlider.oninput = e=>{
timeScale = parseFloat(e.target.value);
document.getElementById('speedVal').textContent = timeScale+'×';
};
/* --- 7. ANIMACIÓN ------------------------------------------- */
let prev = performance.now();
function animate(now){
requestAnimationFrame(animate);
const dt = (now-prev)/1000; // seg reales desde frame anterior
prev = now;
const day = 24*60*60; // seg en un día
pivots.forEach(pivot=>{
const period = pivot.children[0].userData.period*day; // seg por órbita
pivot.rotation.y += dt*timeScale*(2*Math.PI/period)*day; // radianes por seg
});
controls.update();
renderer.render(scene,camera);
}
animate();
/* --- 8. RESPONSIVE ------------------------------------------ */
addEventListener('resize', ()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
</script>
</body>
</html>
Cómo usarlo
• Arrastra con el ratón (o un dedo) para orbitar la cámara.
• Rueda el scroll / pellizca para acercarte a un planeta.
• El deslizador “Velocidad” (0 – 10 ×) controla cuántas veces más rápido que el tiempo real giran las órbitas.
¿Quieres añadir lunas, texturas HD o paneles informativos? Solo añade nuevos pivots o UI, ¡la base ya está lista! 🚀