

import static util.Common.bw1;
import static util.SVGUtil.*;

public class ManyPhyllotaxis {
	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);
	}
	
	private static void drawCard(int n, int i, int j, double ratio) {

		pushMatrix();
		translate(width/2, height/2);
		scale(0.175, 0.175);
		for(int m=1; m<53; m++) {
			stroke(hsl360(ratio*1080, 100, m+25));
			double kaku = m*PHYLLOTAXIS360 + ratio * 360; 
			line(0, 0, 2*m*cos360(kaku), 2*m*sin360(kaku));
		}	
		popMatrix();
	}
	
	public static void main(String[] args) {
		int i, j, n=0;
		double x;
		
		start();
		rulers();
		// ★　以下の３つのうち、どれか一つを選ぶ
//		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();
		return;
	}
}
