import static util.Common.bw1;
import static util.SVGUtil.*;

public class ManyTurtles {
	private static double startX, startY, width, height;
	private static int cols, rows;
	
	private static void CardSpec(double sx, double sy, double dx, double dy, int c, int r) {
		startX = sx; startY = sy; width = dx; height = dy;
		cols = c; rows = r;
	}
	
	private static void CardSpec(double sx, double sy, int c, int r) {
		CardSpec(sx, sy, (pageWidth() - sx * 2) / c , (pageHeight() - sy * 2) / r, c, r);
	}

	private static void init() {
	}

	private static void drawFrame() {
		strokeWeight(0.1);
		stroke(bw1(0));
		noFill();
		rect(0, 0, width, height);
	}
	
	public static void drawCard(int n, int i, int j, double ratio) {
		noStroke();
//		drawFrame();									// デバッグ用
//		fill(hsb360(ratio*360+30, 100, 100));          // ★　色の指定
//		textFont("Times New Roman", 4);
//		text("");
		
		noFill();
		pushMatrix();
		strokeWeight(1);
		translate(width*0.5, height*0.5);
		turtle(n);
		popMatrix();
	}

	public static void turtle(int n) {
		int i;
		go(0, 0);
		penDown();
		for(i=0; i<24; i++) {
			stroke(hsb360(i*15, 100, 100));   /* 色 */
			forward(i*1);                     /* 進む距離 */
			turn(90-4+0.5*n);                         /* 曲がる角度 */
		}
		penUp();
	}
	
	public static void main(String[] args) {
		int i, j, n=0;
		double x;
		start();
		rulers();
		init();
		
//		CardSpec(20, 28, 4, 3);  // A4 縦 3 x 横 4 の場合
		CardSpec(20, 28, 5, 4);    // A4 縦 4 x 横 5 の場合
//		CardSpec(20, 28, 6, 5);    // A4 縦 5 x 横 6 の場合

		x = startX;
		for (i=0; i<cols; i++) {
			double y = startY;
			for (j=0; j<rows; j++, n++) {
				pushMatrix();
				translate(x, y);
				drawCard(n, i, j, (double)n/(cols*rows));
				popMatrix();
				y += height;
			}
			x += width;
		}
		finish();
	}
}
