/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.Wocvq7c7oYs/rev.183
*
* authors:
*
* Mike Kamermans
* annasob
*
*
*
*
*
*
*
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// planetary information: location or area?
boolean[] strip = {false, false, false, false, false,
true,
false, false, false, false, false,
true, true,
false};
// planetary information: names
String[] names = {"sun",
"mercury",
"venus",
"earth",
"mars",
"asteroid belt",
"jupiter",
"saturn",
"uranus",
"neptune",
"pluto",
"kuijper belt",
"oort cloud",
"beyond this, we just don't know"};
// planetary information: body/area size
double[] sizes = {1390000,
4880,
12103.6,
12756.3,
6794,
89758800, // belts are a fair bit wider than planets
142984,
120536,
51118,
49532,
2274,
3590352000.0, // this is a thick belt
7180704000000.0,
1}; // this is an even thicker cloud!
// planetary information: orbits/distances from the sun
double[] orbits = {0,
57910000.0,
108200000.0,
149600000.0,
227940000.0,
314155800.0,
778330000.0,
1429400000.0,
2870990000.0,
4504000000.0,
5913520000.0,
4630000000.0,
299196000000.0,
7479900000000.0};
// sketch information: x-coordinates for the various things
int[] positions = new int[names.length];
// earth's information - not used at the moment
/*
double atmosphere = 100;
double inner_core = 1279;
double outer_core = 2210;
double mantle = 2855;
double crust = 35;
double trench = 10971; // m
double mountain = 8848; // m
*/
int padding = 20;
void setup()
{
size(400,400);
textFont(createFont("Arial",12));
text("",0,0);
ellipseMode(CENTER);
noLoop();
}
void draw()
{
background(255);
stroke(0);
fill(0);
String title = "The solar system is big (left/right click to zoom in/out)";
float ttw = textWidth(title);
text(title,(width-ttw)/2,20);
double f = (double)(width-2*padding) / zoom;
if(strip[strip.length-1]) {
f /= orbits[orbits.length-1] + sizes[sizes.length-1];
}
else {
f /= orbits[orbits.length-1];
}
f = f/zoom;
for(int s=0; s<sizes.length; s++)
{
int x = padding + (int)(orbits[s]*f);
positions[s] = x;
if(!strip[s]) {
strokeWeight(1);
stroke(0);
int r = (int)(sizes[s]*f);
fill(0);
if(r>0) { ellipse(x,height/2,r,r); }
} else {
double start = orbits[s]*f;
double end = start+sizes[s]*f;
double mid = (start+end)/2.0;
strokeWeight((int)(end-start));
stroke(0,100);
noFill();
ellipse(padding, height/2, mid*2.0, mid*2.0);
}
strokeWeight(1);
int y = height/2 + 2 + (strip[s] ? 0 : (int)(sizes[s]*f));
line(x,y,x,y+10);
line(x,y,x-2,y+3);
line(x,y,x+2,y+3);
}
stroke(0);
strokeWeight(1);
line(20,height-20,20,height-10);
line(120,height-20,120,height-10);
noFill(); rect(20,height-20,50,5);
fill(0); rect(70,height-20,50,5);
String label = Math.round(100/f)+" km";
float tw = textWidth(label);
text(label,70-(int)(tw/2),height-25);
lockover=true;
if(over!=-1)
{
stroke(255,0,0,100);
line(positions[over],0,positions[over],height);
fill(0);
text(names[over],mouseX+5,mouseY-6);
}
lockover=false;
}
boolean lockover=false;
int over = -1;
void mouseMoved()
{
if(lockover) return;
for(int s=0; s<positions.length; s++) {
if(abs(mouseX-positions[s])<5) {
over=s;
cursor(HAND);
redraw();
return; }}
over=-1;
cursor(ARROW);
}
double zoom = 0.001953125;
void keyPressed()
{
if(key=='s') { zoom *= 2.0; }
if(key=='w') { zoom /= 2.0; }
redraw();
}
void mouseClicked()
{
if(mouseButton==LEFT) { zoom /= 2.0; }
else if(mouseButton==RIGHT) { zoom *= 2.0; }
redraw();
}