Système solaire

int cx = 250;
int cy = 250;
int r = 100;
int rlune=40;
PImage lune;
PImage soleil;
PImage terre;
PImage asteroide;
PImage sun;
PImage stafield;
PImage espace;
PImage earth;
PImage moon;
PImage explosion;
int xlune=0;
int ylune=0;
int xasteroide=0;
int yasteroide=0;
int aasteroide=110;
int basteroide=90;
int [] positionLuneX;
int [] positionLuneY;
int compteurPositionlune=0;
PShape globe;
PShape globeT;
PShape globeL;
PShape globeE;
PShape globeA;
void setup()
{
size(500, 500, P3D);noStroke();
fill(255);
sphereDetail(40);
creation_espace();
creation_sun();
creation_asteroide();
creation_earth();
creation_moon();}
void draw()
{
background(0);
camera(width/2, mouseY, mouseX, width/2, height/2, 0, 0, 1, 0);
affichage_espace();
affichage_sun();
affichage_asteroide();
affichage_earth();
affichage_moon();
affichage_texte();
}
void affichage_astre( PImage astre, int positionX, int positionY, int tailleX, int tailleY) {
image (astre, positionX, positionY, tailleX, tailleY);
}

void creation_asteroide(){
asteroide=loadImage("asteroide2.png");
explosion=loadImage("explosion.png");
noStroke();
globeA= createShape(SPHERE, 10);
globeA.setTexture(asteroide);
}
void affichage_asteroide(){
float t = 0.5*millis()/1000.0f;
int x = (int)(cx+r*cos(t));
int y = (int)(cy+r*sin(t));int xasteroide = (int)(cx+2*aasteroide*cos(0.89*t+ PI));
int yasteroide = (int)(cy+1*basteroide*sin(0.89*t+PI));noFill();
ellipse(cx,cy,aasteroide*4, basteroide*4/2);pushMatrix();
translate(xasteroide,yasteroide,0);
rotateY(PI/20);
noStroke();
shape(globeA,0,0,20,10);
stroke(255);
popMatrix();
if ( xasteroide>x-10 && xasteroide<x+10 && yasteroide>y-10 && yasteroide<y+10) {
noLoop();
text("Collision", 110, 110);
image(explosion,xasteroide-45,yasteroide-40,70,70);
}
}

void creation_earth(){
earth=loadImage("earth_daymap.jpg");noStroke();
globeT= createShape(SPHERE, 25);
globeT.setTexture(earth);
}
void affichage_earth(){
float t = 0.5*millis()/1000.0f;
int x = (int)(cx+r*cos(t));
int y = (int)(cy+r*sin(t));
noFill();
ellipse(cx, cy, r*4/2, r*4/2);
pushMatrix();
translate(x,y,0);
rotateY(PI*frameCount/750);
noStroke();
shape(globeT);
stroke(255);
popMatrix();
}

void creation_espace(){
espace=loadImage("espace.jpg");
noStroke();
globeE = createShape(SPHERE, 2500);
globeE.setTexture(espace);
}
void affichage_espace(){
pushMatrix();
translate(250,250,0);
//rotateY(PI*frameCount/750);
noStroke();
shape(globeE);
stroke(255);
popMatrix();
}

void creation_moon(){
moon=loadImage("moon.jpg");
noStroke();
globeL= createShape (SPHERE, 5);
globeL.setTexture(moon);
positionLuneX = new int [0];
positionLuneY = new int [0];
}
void affichage_moon(){
float t = 0.5*millis()/1000.0f;
int x = (int)(cx+r*cos(t));
int y = (int)(cy+r*sin(t));
int xlune = (int)(x+rlune*cos(12*t));
int ylune = (int)(y+rlune*sin(12*t));
//positionLuneX[compteurPositionlune]=xlune;
positionLuneX= append(positionLuneX, xlune);
positionLuneY= append(positionLuneY, ylune);
println(positionLuneX.length);
for (int i=0; i<positionLuneX.length-1; i++) {
point(positionLuneX[i], positionLuneY[i]);
}
//positionLuneY[compteurPositionlune]=ylune;
compteurPositionlune++;
pushMatrix();
translate(xlune,ylune,0);
rotateY(PI*frameCount/1500000);
noStroke();
shape(globeL);
stroke(255);
popMatrix();
}

void creation_sun(){
sun=loadImage("sun.jpg");
noStroke();
globe = createShape(SPHERE, 35);
globe.setTexture(sun);
}
void affichage_sun(){
pushMatrix();
translate(250, 250, 0);
//directionalLight(255, 255, 0, 10, -1, 0);
//ambientLight(0,0,255);
//texture(soleil);
//pointLight(255, 255, 0, width/2, height/2, 3000);
rotateY(PI * frameCount / 500);
noStroke();
shape(globe);
stroke(255);
//sphere(25);
popMatrix();
}

void affichage_texte(){
text("(99942) Apophis en collision avec la Terre 13 avril 2036 ?", 20, 20);
text(" L'astéroïde mesurant moins d'un kilomètre de diamètre, ", 20, 50);
text("son impact n'aurait eu que des conséquences « régionales »", 20, 80);
text("demi-grand axe = 0.92 ua; période= 0,89 a", 20, 470);
text("périhélie 0.9 ua, aphélie = 1,1 ua", 20, 440);
text("inclinaison 3,3°", 20, 410);
}

Créez votre site web gratuitement ! Ce site internet a été réalisé avec Webnode. Créez le votre gratuitement aujourd'hui ! Commencer