//Fill in the blank program for PCS 5th grade about planetary motion
//Students must modify the values of the planet variables to be the
//number of Earth days for each planets solar orbit
//currently they are all set to match earth's orbit of 365 days
//Z.J. Wood - 2014

//some variables for use in the program
//the planet path colors
color[] TheCs = new color[8];
int EY;

//the planet speeds
float Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune;
//daily speed
float E_theta, M_theta, V_theta, Mars_theta, J_theta, S_theta, U_theta, N_theta;


//set up some basic draw parameters
void setup() {
  EY = 0;
  size(700, 300);
  smooth();
  background(0);
  for (int i=0; i < 8; i++) {
    color c = color(random(0, 255), random(0, 255), random(0, 255));
    TheCs[i] = c;
  }
  
  //TODO for students - replace each planet's speed with the correct number
  Mercury = 365;
  Venus = 365;
  Earth = 365;
  Mars = 365;
  Jupiter = 365;
  Saturn = 365;
  Uranus = 365;
  Neptune = 365;
  
    
  //initialize the planet speeds
  E_theta = M_theta = V_theta = Mars_theta = 0;
  J_theta = S_theta = U_theta = N_theta = 0;
}


//helper function to draw the path of each planet's orbit
void draw_path(int cx, int cy, float r1, float r2, int p, float theta) {

  float x, y;
 
  stroke(TheCs[p]);
  fill(TheCs[p]);
  x = r1*cos(theta) + cx;
  y = r2*sin(theta) + cy;
  ellipse(x, y, 2, 3);
}

//the main draw loop
void draw() {
  
  int p = 0;
  int cx = 350;
  int cy = 150;
  float sc = 1.2;


  
  if (N_theta > 2*PI) {
    background(0);
    M_theta = V_theta = E_theta = Mars_theta = 0;
      J_theta = S_theta = U_theta = N_theta = 0;
  }
  if (E_theta > TWO_PI) {
    EY += 1;
    M_theta = V_theta = E_theta =0;
    for (int i=0; i < 3; i++) {
        color c = color(random(0, 255), random(0, 255), random(0, 255));
        TheCs[i] = c;
    }
  }
  noStroke();
  fill(#FADA23);
  ellipse(cx, cy, 10, 10);
  //draw each planet's path - ellipitical orbit paths are estimates
  draw_path(cx, cy, 26*sc, 8*sc, 0, M_theta);
  draw_path(cx, cy, 36*sc, 10*sc, 1, V_theta);
  draw_path(cx, cy, 46*sc, 14*sc, 2, E_theta);
  draw_path(cx, cy, 52*sc, 18*sc, 3, Mars_theta);
  draw_path(cx, cy, 102*sc, 40*sc, 4, J_theta);
  draw_path(cx, cy, 124*sc, 50*sc, 5, S_theta);
  draw_path(cx, cy, 230*sc, 79*sc, 6, U_theta);
  draw_path(cx, cy, 280*sc, 95*sc, 7, N_theta);
  E_theta += TWO_PI/Earth;
  M_theta +=TWO_PI/Mercury;
  V_theta += TWO_PI/Venus;
  Mars_theta += TWO_PI/Mars;
  J_theta += TWO_PI/Jupiter;
  S_theta += TWO_PI/Saturn;
  U_theta += TWO_PI/Uranus;
  N_theta += TWO_PI/Neptune;
  
  for (int ey=0; ey < EY; ey++) {
    fill(255);
    rect(ey*10+4, 10, 10, 10);
  }
}