2013年4月21日 星期日

2013資訊設計 processing 製作2/ m10110302 林秉毅


八大行星公轉




planet sun; //太陽
planet mercury; //水星
planet venus; //金星
planet earth;//地球
planet mars;//火星
planet jupiter;//木星
planet satum; //土星
planet uranus; //天王星
planet neptune; //海王星

//nine planets!

float xc, yc;
float cc;
void setup() {
  size(950,950);
  xc=width/2;
  yc=height/2;
  // 行星中心點
  cc=0.15;
   mercury = new planet(color(0,0,0),39,38.,360,4.7,2);
  venus  = new planet(color(0,0,0),72,71.9,360,3.5,7);
  earth  = new planet(color(0,255,0),100,99.9,360,3.5,8);
  mars  = new planet(color(255,0,0),150,149.3,360,2.4,4);
  jupiter  = new planet(color(0,0,0),520,519.3,360,1.3,40);
  satum  = new planet(color(0,0,0),950,948.4,360,0.9,25);
  uranus  = new planet(color(0,0,0),1900,1917.8,360,0.6,20);
  neptune  = new planet(color(0,0,0),3001,3000.9,360,0.5,15);
}

void draw() {
  background(0);
  mercury.drive();
  mercury.display();
  venus.drive();
  venus.display();
  earth.drive();
  earth.display();
  mars.drive();
  mars.display();
  jupiter.drive();
  jupiter.display();
  satum.drive();
  satum.display();
  uranus.drive();
  uranus.display();
  neptune.drive();
  neptune.display();
}

// Even though there are multiple objects, we still only need one class.
// No matter how many cookies we make, only one cookie cutter is needed.
class planet {
  color c;
  float xi; //
  float yi;
  float N;
  float AU;//軌道半長軸
  float BU;//軌道半短軸
  float speed;
  float count=0;
  float jen;
  float jenS;
  float size;

  // The Constructor is defined with arguments.
  planet(color tempC, float AUi,float BUi, float Ni,float speedi, float sizei) {
    c = tempC;
    N = Ni;
    AU=cc*AUi;
    BU=cc*BUi;
    speed=speedi;
    jen=AU/(N/speed);
    size=sizei;
    jenS=size/(N/speed);
 
}

  void display() {
    stroke(255);
    fill(255);  
    ellipse(xc+AU*cos(count*2*PI/N),yc+BU*sin(count*2*PI/N),size,size);
   
    stroke(255);
    noFill();
    ellipseMode(RADIUS);
    ellipse(xc,yc,AU,BU);
  }

  void drive() {
   
   
    count +=speed;
 
    if (count >= N) {
      count = 0;
     
   
    }
  }
}

沒有留言:

張貼留言