System sol; void setup(){ size(640, 480); sol = new System(width/2, height/2); } void draw(){ sol.update(); background(0,0,0); sol.draw(); } class Planet { //float r3,r,nu,v,hz,h,e; private float x; private float y; private float xVelocity; private float yVelocity; //private float energy; //private float period; private float starMass; private float r; private float r3; Planet(float inStarMass) { x = 100; y = 0; xVelocity = 0; yVelocity = 10; //v = 0; r = sqrt((x*x) + (y*y)); r3 = 1/(r*r*r); //nu = 0; starMass = inStarMass; } void update() { //hz = (x * yVelocity) - (y * xVelocity); //energy = ((v*v)/2) - (starMass/r); //e = sqrt(1+ ((2*energy*hz*hz)/(starMass*starMass))); //v = sqrt((xVelocity*xVelocity) + (yVelocity*yVelocity)); //period = (hz * hz) / starMass; //nu = acos(((period/r) - 1)/e); xVelocity -= starMass * x * r3; yVelocity -= starMass * y * r3; x += xVelocity; y += yVelocity; r = sqrt((x*x) + (y*y)); r3 = 1/(r*r*r); } float getX() { return x; } float getY() { return y; } void draw() { stroke(0,255,0); noFill(); ellipse(x,y,10,10); } } class Star { private float x; private float y; private float mass; private float diameter; public Star() { x = 0; y = 0; mass = 7000; diameter = 70; } public float getMass() { return mass; } public void update() { } public void draw() { stroke(255,255,0); noFill(); ellipse(x,y,diameter,diameter); } } class System { private float x; private float y; private Star star; private Planet[] planets; public System(float inX, float inY) { x = inX; y = inY; star = new Star(); planets = new Planet[1]; for(int i = 0; i < planets.length; i++) { planets[i] = new Planet(star.getMass()); } } public void update() { star.update(); for(int i = 0; i < planets.length; i++) { planets[i].update(); } } public void draw() { translate(x, y); translate(-(planets[0].getX() / 70), -(planets[0].getY() / 70)); star.draw(); for(int i = 0; i < planets.length; i++) { planets[i].draw(); } } }