2. คำนวณ

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.

 
รหัสที่ 2-18  โปรแกรมลากเส้นที่กำหนดด้วยจุดเริ่ม ความยาวเส้น และมุม
import jlab.graphics.DWindow;

public class LineDrawing {
  public static void main(String[] args) {
    int width = 200, height = 100, len = 90;
    DWindow w = new DWindow(width, height);
    double x0 = width / 2, y0 = height - 10;
    double x1, y1, angle = 45, delta = 90;
    //---------------------------------------------
    x1 = x0 + len * Math.cos(Math.toRadians(angle));
    y1 = y0 - len * Math.sin(Math.toRadians(angle));
    w.drawLine(x0, y0, x1, y1);
    //---------------------------------------------
    angle = angle + delta;
    x1 = x0 + len * Math.cos(Math.toRadians(angle));
    y1 = y0 - len * Math.sin(Math.toRadians(angle));
    w.drawLine(x0, y0, x1, y1);
  }
}
©2009 S.Prasitjutrakul