9. สร้างใหม่จากเก่า

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 9-14  ตัวอย่างโปรแกรมการใช้ Ball3D กับ DWindow3D
public class TestBall3D {
  public static void main(String[] args) {
    DWindow3D w3 = new DWindow3D(200, 200, 200);
    Ball3D[] balls = new Ball3D[1];  // ผู้อ่านลองสร้างหลายลูกดูเอง 
    for (int i = 0; i < balls.length; i++) {
      balls[i] = new Ball3D(20, 100, 100, 100);
      balls[i].setGravity(3*Math.random());
    }
    w3.setRepaintDuringSleep(true);
    while (true) {
      w3.clearBackground();   
      w3.drawFrame(50);
      for (int i = 0; i < balls.length; i++) {
        balls[i].move(w3);   
        balls[i].draw(w3);
      }
      w3.sleep(50);
    }
  }
}
©2009 S.Prasitjutrakul