xxxxxxxxxx
559
let creadapantalla = 0;
var fondo;
let X0 = 0, Y0 = 0, Z0 = 0; // coordenadas del Sol.
let X11 = 0, Y11 = 0, Z11 = 0;
(X7 = 0), (Y7 = 0), (Z7 = 0); // coordenadas de Mercurio.
(X8 = 0), (Y8 = 0), (Z8 = 0); // coordenadas de Venus.
(X1 = 0), (Y1 = 0), (Z1 = 0); // coordenadas de la Tierra.
(X2 = 0), (Y2 = 0), (Z2 = 0); // Coordenadas de la Luna.
(X3 = 0), (Y3 = 0), (Z3 = 0); // coordenadas de Marte.
(X4 = 0), (Y4 = 0), (Z4 = 0); // coordenadas de Deimos.
(X5 = 0), (Y5 = 0), (Z5 = 0); // coordenadas de Fobos.
(X3B = 0), (Y3B = 0), (Z3B = 0); // coordenadas asteroides.
(X6 = 0), (Y6 = 0), (Z6 = 0); // coordenadas de Jupiter.
(X7 = 0), (Y7 = 0), (Z7 = 0); // coordenadas de Io.
(X8 = 0), (Y8 = 0), (Z8 = 0); // coordenadas de Europa.
(X9 = 0), (Y9 = 0), (Z9 = 0); // coordenadas de Ganimedes.
(X10 = 0), (Y10 = 0), (Z10 = 0); // coordenadas de Calixto.
(X15 = 0), (Y15 = 0), (Z15 = 0); // coordenadas de Saturno.
(X12 = 0), (Y12 = 0), (Z12 = 0); // coordenadas de Urano.
(X13 = 0), (Y13 = 0), (Z13 = 0); // coordenadas de Neptuno.
(X14 = 0), (Y14 = 0), (Z14 = 0); // coordenadas de Plutón.
let anguloRevolucion = 20; // Ángulo de revolución.
let anguloRotacion = 0; // Ángulo de rotación.
let radioRevolucion = 300; // Radio de revolución.
let sol, mercurio, venus, tierra, luna, marte, deimos, fobos, jupiter, io, europa, ganimedes, calixto, saturno, urano, neptuno, pluton; // Carga mapa
let asteroides = []; // Carga los asteroides
let camaraX, camaraY, camaraZ = 700; // Coloca la cámara
function preload() {
fondo = loadImage("imagenes/fondoest.jpg");
musica = loadSound("sonidos/musica.mp3");
sol = loadImage("imagenes/sol.png");
mercurio = loadImage("imagenes/mercurio.png");
venus = loadImage("imagenes/venus.png");
tierra = loadImage("imagenes/tierra.png");
luna = loadImage("imagenes/luna.png");
marte = loadImage("imagenes/marte.png");
deimos = loadImage("imagenes/deimos.png");
fobos = loadImage("imagenes/fobos.png");
jupiter = loadImage("imagenes/jupiter.png");
io = loadImage("imagenes/io.jpeg");
europa = loadImage("imagenes/europa.jpg");
ganimedes = loadImage("imagenes/ganimedes.jpeg");
calixto = loadImage("imagenes/calixto.jpeg");
saturno = loadImage("imagenes/saturno.jpg");
urano = loadImage("imagenes/urano.jpg");
neptuno = loadImage("imagenes/neptuno.jpg");
pluton = loadImage("imagenes/pluton.jpg");
}
function setup() {
let recuadroproyecto = createCanvas(1000, 1000, WEBGL);
musica.play();
//Crear los asteroides
for (let i = 0; i < 300; i++) {
asteroides.push({
x: 0,
y: 0,
offset: Math.random() * 360,
orbit: (Math.random() + 0.01) * max(width / 4, height / 4),
radius: Math.random() * 0.02,
vx: Math.floor(Math.random()) - 5,
vy: Math.floor(Math.random()) - 5,
});
}
}
function draw() {
clear();
background(0);
drawfondo();
setLuz();
drawsol();
drawmercurio();
drawvenus();
drawmarte();
drawtierra();
drawluna();
drawdeimos();
drawio();
draweuropa();
drawganimedes();
drawcalixto();
drawfobos();
drawjupiter();
drawsaturno();
drawurano();
drawneptuno();
drawpluton();
drawasteroides();
//Posición de la cámara
camaraX = mouseX + width / 2.5;
camaraY = mouseY + height / 2.5;
camera(camaraX, camaraY - 2000, camaraZ + 3000, 0, 0, 0, 0, 1, 0);
noStroke();
anguloRotacion += 0.01;
}
function drawfondo() {
push();
texture(fondo);
sphere(4300);
pop();
}
function drawsol() {
push();
translate(X0, X0, Z0);
fill(0, 255, 255);
texture(sol);
ambientLight(100000, 100000, 100000, 100000);
rotateY(anguloRotacion / 5);
sphere(200);
pop();
//Órbita de Mercurio
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(240, 0.7, 240);
pop();
//Órbita de Venus
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(400, 0.7, 240);
pop();
//Órbita de la Tierra
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(800, 0.7, 240);
pop();
// órbita de Marte
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(1600, 0.7, 240);
pop();
// órbita de Júpiter
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(3200, 0.7, 240);
pop();
anguloRevolucion += 0.005;
//Órbita de Saturno
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(3600, 0.7, 240);
pop();
//Órbita de Urano
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(3800, 0.7, 240);
pop();
//Órbita de Neptuno
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(4000, 0.7, 240);
pop();
//Órbita de Plutón
push();
translate(X0, Y0, Z0);
rotateX((PI / 180) * 90);
fill(240);
torus(4200, 0.7, 240);
pop();
}
function drawmercurio() {
X7 = X0 + 240 * cos(anguloRevolucion);
Z7 = Z0 + 240 * sin(anguloRevolucion);
push();
translate(X7, Y7, Z7);
rotateY(anguloRotacion / 4);
texture(mercurio);
sphere(10);
pop();
}
function drawvenus() {
X8 = X0 + 400 * cos(anguloRevolucion / 2);
Z8 = Z0 + 400 * sin(anguloRevolucion / 2);
push();
translate(X8, Y8, Z8);
rotateY(anguloRotacion / 4);
texture(venus);
sphere(40);
pop();
}
function drawtierra() {
X1 = X0 + 800 * cos(anguloRevolucion / 3);
Z1 = Z0 + 800 * sin(anguloRevolucion / 3);
push();
translate(X1, Y1, Z1);
rotateY(anguloRotacion);
texture(tierra);
sphere(40);
pop();
//Órbita de la Luna
push();
translate(X1, Y1, Z1);
rotateX((PI / 180) * 90);
fill(240);
torus(60, 0.7, 240);
pop();
anguloRevolucion += 0.005;
}
function drawluna() {
X2 = X1 + 60 * cos(anguloRevolucion * 2);
Z2 = Z1 + 60 * sin(anguloRevolucion * 2);
push();
translate(X2, Y2, Z2);
rotateY(-anguloRotacion);
texture(luna);
sphere(10);
pop();
}
function drawmarte() {
X3 = X0 + 1600 * cos(anguloRevolucion / 3);
Z3 = Z0 + 1600 * sin(anguloRevolucion / 3);
push();
translate(X3, Y3, Z3);
rotateY(anguloRotacion);
texture(marte);
sphere(20);
pop();
}
function drawdeimos() {
X4 = X3 + 60 * cos(anguloRevolucion * 5);
Z4 = Z3 + 60 * sin(anguloRevolucion * 5);
push();
translate(X4, Y4, Z4);
rotateY(-anguloRotacion);
texture(deimos);
sphere(5);
pop();
}
function drawfobos() {
X5 = X3 + 80 * cos(anguloRevolucion * 3);
Z5 = Z3 + 80 * sin(anguloRevolucion * 3);
push();
translate(X5, Y5, Z5);
rotateY(-anguloRotacion);
texture(fobos);
sphere(5);
pop();
//Órbita de Deimos
push();
translate(X3, Y3, Z3);
rotateX((PI / 180) * 90);
fill(240);
torus(60, 0.7, 240);
pop();
anguloRevolucion += 0.005;
//Órbita de Fobos
push();
translate(X3, Y3, Z3);
rotateX((PI / 180) * 90);
fill(240);
torus(60, 0.7, 240);
pop();
anguloRevolucion += 0.005;
}
function drawjupiter() {
X6 = X0 + 3200 * cos(anguloRevolucion / 5);
Z6 = Z0 + 3200 * sin(anguloRevolucion / 5);
push();
translate(X6, Y6, Z6);
rotateY(anguloRotacion);
texture(jupiter);
sphere(160);
pop();
push();
translate(X6, Y6, Z6);
rotateX((PI / 180) * 90);
fill(240);
torus(200, 0.7, 240);
pop();
anguloRevolucion += 0.005;
push();
translate(X6, Y6, Z6);
rotateX((PI / 180) * 90);
fill(240);
torus(250, 0.7, 240);
pop();
anguloRevolucion += 0.005;
push();
translate(X6, Y6, Z6);
rotateX((PI / 180) * 90);
fill(240);
torus(300, 0.7, 240);
pop();
anguloRevolucion += 0.005;
push();
translate(X6, Y6, Z6);
rotateX((PI / 180) * 90);
fill(240);
torus(350, 0.7, 240);
pop();
anguloRevolucion += 0.005;
}
function drawio() {
X7 = X6 + 200 * cos(anguloRevolucion);
Z7 = Z6 + 200 * sin(anguloRevolucion);
push();
translate(X7, Y7, Z7);
rotateY(-anguloRotacion);
texture(io);
sphere(10);
pop();
}
function draweuropa() {
X8 = X6 + 250 * cos(anguloRevolucion / 2);
Z8 = Z6 + 250 * sin(anguloRevolucion / 2);
push();
translate(X8, Y8, Z8);
rotateY(-anguloRotacion);
texture(europa);
sphere(10);
pop();
}
function drawganimedes() {
X9 = X6 + 300 * cos(anguloRevolucion / 3);
Z9 = Z6 + 300 * sin(anguloRevolucion / 3);
push();
translate(X9, Y9, Z9);
rotateY(-anguloRotacion);
texture(ganimedes);
sphere(10);
pop();
}
function drawcalixto() {
X10 = X6 + 350 * cos(anguloRevolucion / 4);
Z10 = Z6 + 350 * sin(anguloRevolucion / 4);
push();
translate(X10, Y10, Z10);
rotateY(-anguloRotacion);
texture(calixto);
sphere(10);
pop();
}
function drawsaturno() {
X15 = X0 + 3600 * cos(anguloRevolucion / 4);
Z15 = Z0 + 3600 * sin(anguloRevolucion / 4);
push();
translate(X15, Y15, Z15);
rotateY(anguloRotacion);
texture(saturno);
sphere(100);
pop();
//Anillo 1
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(100, 1.7, 255);
pop();
//Anillo 2
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(110, 1.7, 255);
pop();
//Anillo 3
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(120, 1.7, 255);
pop();
//Anillo 4
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(130, 1.7, 255);
pop();
//Anillo 5
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(140, 1.7, 255);
pop();
//Anillo 6
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(150, 1.7, 255);
pop();
//Anillo 7
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(160, 1.7, 255);
pop();
//Anillo 8
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(170, 1.7, 255);
pop();
//Anillo 9
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(180, 1.7, 255);
pop();
//Anillo 10
push();
translate(X15, Y15, Z15);
rotateX((PI / 180) * 60);
fill(255);
torus(190, 1.7, 255);
pop();
}
function drawurano() {
X12 = X0 + 3800 * cos(anguloRevolucion / 7);
Z12 = Z0 + 3800 * sin(anguloRevolucion / 7);
push();
translate(X12, Y12, Z12);
rotateY(anguloRotacion);
texture(urano);
sphere(80);
pop();
//Anillo 1 Urano
push();
translate(X12, Y12, Z12);
rotateX(PI / 180);
fill(240);
torus(100, 0.7, 255);
pop();
//Anillo 2 Urano
push();
translate(X12, Y12, Z12);
rotateX(PI / 180);
fill(255);
torus(110, 0.7, 255);
pop();
}
function drawneptuno() {
X13 = X0 + 4000 * cos(anguloRevolucion / 9);
Z13 = Z0 + 4000 * sin(anguloRevolucion / 9);
push();
translate(X13, Y13, Z13);
rotateY(anguloRotacion);
texture(neptuno);
sphere(70);
pop();
}
function drawpluton() {
X14 = X0 + 4200 * cos(anguloRevolucion / 13);
Z14 = Z0 + 4200 * sin(anguloRevolucion / 13);
push();
translate(X14, Y14, Z14);
rotateY(anguloRotacion);
texture(pluton);
sphere(10);
pop();
}
function drawasteroides() {
colorMode(RGB, 255, 255, 255, 1);
for (let i = 0; i < asteroides.length; i++) {
let s = asteroides[i];
push();
X3B = X0 + 2400 * cos(anguloRevolucion / 10);
Z3B = Z0 + 2400 * sin(anguloRevolucion / 10);
translate(X3B + s.x, Y3B + s.y, Z3B);
sphere(5);
pop();
}
update();
}
function update() {
for (let i = 0; i < asteroides.length; i++) {
let s = asteroides[i];
let rad = (frameCount * (1 / (s.orbit * 2 + s.offset)) + s.offset) % TAU; // tamaño de nube
s.x = Z3B + cos(rad) * (s.orbit * 2) * 3;
s.y = Y3B + sin(rad) * s.orbit * 3;
}
}
function setLuz() {
pointLight(255, 255, 255, 0, 0, 0);
ambientLight(0);
}
function mouseWheel(event) {
if (event.deltaY > 0) {
camaraZ += 100;
} else {
camaraZ -= 100;
}
}