123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- 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();
- }
- }
- }
|