import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; public class solarSystem1 extends BApplet { // solar system study // // click rotates to side-on view and zooms in towards sun // // moons have been removed for sake of speed int zoom = -2500; int zoomIncr = 25; float a,b; float xMouse, yMouse; int totalPlanets = 9; Planet[] planet = new Planet[totalPlanets]; float[] periods = {0.479f, 0.35f, 0.298f, 0.241f, 0.131f, 0.096f, 0.068f, 0.054f, 0.047f}; float[] distSun = {0.39f, 0.72f, 1.00f, 1.52f, 5.20f, 9.54f, 19.18f, 30.06f, 39.44f}; float[] sizes = {4.878f, 12.102f, 12.756f, 6.787f, 142.8f, 120.6f, 52.4f, 50.0f, 3.0f}; int[] reds = {200,200,1,255,150,125,1,1,150}; int[] greens = {180,255,100,50,100,150,1,175,150}; int[] blues = {100,100,255,1,1,50,255,255,150}; boolean click; void setup(){ size(400,400); background(0,0,51); noStroke(); lights(); ellipseMode(CENTER_RADIUS); g.lightKind[2] = AMBIENT; g.lightX[2] = 0; g.lightY[2] = 0; g.lightZ[2] = 0; g.lightR[2] = 1; g.lightG[2] = 1; g.lightB[2] = 0; g.lightKind[3] = DIFFUSE; g.lightX[3] = 0; g.lightY[3] = 0; g.lightZ[3] = 0; g.lightR[3] = 1; g.lightG[3] = 1; g.lightB[3] = 0; for (int i=0; i -2500){ zoom -= zoomIncr; } if (click){ // orients to side view on click a -= (a - 0) * .2f; b -= (b - HALF_PI) * .2f; } else { a += xMouse / 1000.0f; b += yMouse / 1000.0f; if (a > PI){ a -= TWO_PI; } else if (a < -PI){ a += TWO_PI; } if (b > PI){ b -= TWO_PI; } else if (b < -PI){ b += TWO_PI; } } translate(width/2, height/2, zoom); rotateX(b); rotateY(a); // draw sun fill(255, 255, 0); sphere(100); for (int i=0; i PI){ orbit -= TWO_PI; } rotateZ(orbit); translate(distSun,0,0); // sad and sloppy 3D clipping bandaid if (objectZ(0,0,0) < 250){ render(); } } void render(){ noStroke(); fill(r,g,b); sphere(mass); // add ring to Saturn (i know i know, jupiter and uranus and possibly neptune have rings too) if (index == 5){ rotateY(0.4f); fill(r/2, g/2, b/2, 100); ellipse(0,0,mass*2.20f, mass*2.20f); } } } }