I used this project as a test bed to try different ideas and see the visual effects.
-When the mouse is pressed, the orbits of the Moon and the fictitious asteroid change, even if there is nothing in the function called by mouse pressed. Why?
- I could only manage to draw a few mountains by inscribing boxes inside of it and making the corners visible. How can I make other drawings in the surface of the sphere (Earth)? Like text for example?
- How can I make the axis round instead of a very long and thin box? Any ideas??
In the video, the mouse pressed function was not present and the magnetic field is always visible.
int W=1350; //Earth-Moon System by Adrian Fernandez 04-09-2013
int H=700;
float i=0; //Angular variable
float OrbitWidth=700;
float OrbitHoizInclination=7;
float Speed=0.007;
float r=0;
void setup()
{
size(W,H,P3D);
}
void draw()
{
background(5);
camera(mouseX, mouseY, 220.0, width/2,height/2,-OrbitWidth/2, 0.1,1, 0.1); //Move the camera with the mouse.
directionalLight(255, 255, 255, -1, 0,-0.25);
translate(width/2,height/2,-OrbitWidth/2); //Positions Earth at center.
rotate(0.1);
rotateY(frameCount/200.0); //To rotate the Earth
fill(0,200,255);
noStroke();
sphereDetail(30); //Sets more detail for the Earth Sphere a it is bigger.
sphere(121); //Draws Earth Sphere
fill(255);
rotate(0.15);
box(142);
rotate(0.20);
box(142);
rotate(-0.20);
rotate(0.15);
box(142);
fill(255);
box(5,600,5);
if(mousePressed)//Click to see mag field.
{
rotate(-0.15); //Makes the magnetig field appear off center
ShowMagneticField();
}
rotateY(-frameCount/200.0); //Stops rotation before the next spheres are drawn.
i=(i+Speed)%TWO_PI; //Sets angle between 0 and 2*PI.
fill(250);
translate(3*OrbitWidth/2*cos(i),OrbitWidth/OrbitHoizInclination*cos(i),-3*OrbitWidth/2-2*OrbitWidth*sin(i)); //Moon coordinates
noStroke();
sphereDetail(20); //Sets less detail for the Moon.
sphere(45); //Draws Moon Sphere.
translate(OrbitWidth*cos(1.19*i)+(W/1.5),1.1*OrbitWidth/OrbitHoizInclination*cos(i/5),OrbitWidth/2-OrbitWidth*sin(i)+270); //Asteroid coordinates
rotate(2);
fill(220);
sphereDetail(6); //Sets less detail for the Asteroid to make it look rocky.
sphere(20); //Draws Asteroid Sphere.
}
void ShowMagneticField()
{
noFill();
strokeWeight(0.5);
for(int k=10;k<360;k=k+10)
{
rotateY(k);
stroke(255,k,0);
ellipse(100,0,250,380);
stroke(0,k,255);
ellipse(-100,0,250,380);
}
rotateY(-350);
}