package image;

import stdlib.Color;
import stdlib.StdDraw;

 /**
 * Create an N-by-N hexagonal tile.
 */
public class HexTile {
	static StdDraw sd = new StdDraw();
    public static void hexagon(double x, double y, double size) {
        double c1 = Math.sqrt(3) / 2;
        double c2 = .5;
        double[] px = { x + c1*size, x + c1*size, x,        x - c1*size, x - c1*size, x        };
        double[] py = { y - c2*size, y + c2*size, y + size, y + c2*size, y - c2*size, y - size };
        StdDraw.polygon(px, py);
    }

    public static void filledHexagon(double x, double y, double size) {
        double c1 = Math.sqrt(3) / 2;
        double c2 = .5;
        double[] px = { x + c1*size, x + c1*size, x,        x - c1*size, x - c1*size, x        };
        double[] py = { y - c2*size, y + c2*size, y + size, y + c2*size, y - c2*size, y - size };
        StdDraw.filledPolygon(px, py);
    }

    public static void main(String[] args) {
        double c = Math.sqrt(3) / 2;
//        int N = Integer.parseInt(args[0]);
        int N = 10;
        sd.setCanvasSize(900, 600);
        sd.setXscale(-1, 3*N/2);
        sd.setYscale(-1, N);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                sd.setPenRadius();
                sd.setPenColor(Color.BLACK);
                filledHexagon(i+.5*j, j*c, .5/c);
                sd.setPenRadius(.005);
                sd.setPenColor(Color.WHITE);
                hexagon(i+.5*j, j*c, .5/c);
            }
        }
    }                
}
