6. á¡ÂèÍÂ

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.

 
ÃËÑÊ·Õè 6-11  àÁ·çÍ´ÇÒ´ÃÙ»ÊÕèàËÅÕèÂÁ¨ÑµØÃÑÊ
import jlab.graphics.DWindow;

public class Drawing {
  public static void main(String[] args) {
    DWindow w = new DWindow(200, 200);
    for (int a = 0; a < 90; a = a + 10) {
      drawSquare(w, 100, 100, 120, a);
    }
  }
  public static double sin(double a) {
    return Math.sin(Math.toRadians(a));
  }
  public static double cos(double a) {
    return Math.cos(Math.toRadians(a));    
  }
  public static void drawSquare(DWindow w, int xc, int yc,
                                int d, int a) {
    double r = d / (2 * cos(45));
    double angle = a - 45;
    double x0 = xc + r * cos(angle);
    double y0 = yc - r * sin(angle);
    for (int i = 0; i < 4; i++) {
      angle = angle + 90;
      double x1 = xc + r * cos(angle);
      double y1 = yc - r * sin(angle);
      w.drawLine(x0, y0, x1, y1);
      x0 = x1; y0 = y1;
    }
  }
©2009 S.Prasitjutrakul