7. แถวลำดับ

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.

 
รหัสที่ 7-29  ตัวอย่างการใช้เมท็อดจัดการสีและแผนที่จุดภาพ
import jlab.graphics.DWindow;
public class FillPattern {
  public static void main(String[] args) {
    DWindow w = new DWindow(256,256);
    int[][] p = w.getPixmap();
    int d = 16;
    for (int x = 0; x < p.length; x+=d) {
      for (int y = 0; y < p[0].length; y+=d) {
        int c = DWindow.mixRGB(y,y,y);
        fillPattern(p, x, y, d, c);
      }
    }
    w.setPixmap(p);
  }
  public static void fillPattern(int[][] p, int x0, int y0,
                                 int d, int c) {
    for (int x = 0; x < d; x++) {
      for (int y = 0; y < d; y++) {
        if (x > y)
          p[x0 + x][y0 + y] = c;
        else
          p[x0 + x][y0 + y] = DWindow.WHITE;
      }
    }
  }
}
©2009 S.Prasitjutrakul