import static util.SVGUtil.*;

public class CardGraph2 {
	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 init() {
	}

	// 調整用の枠線を描く
	public 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) {
		int t;
		double delta = 10;                                   // ★　色相の変化量

		drawFrame();                                         // ★　調整用の枠線、印刷するときは、この行をコメントアウトする。 
		fillOpacity(1);
		noStroke();

		fill(hsb360(ratio * 360, 100, 100));
		textFont("MS-Mincho", 8);
		text("讃岐 太郎", 10, 20);

		fill(hsb360(ratio * 360+delta * 1, 100, 100));
		textFont("MS-Mincho", 6);
		text("香川大学創造工学部", 10, 28);

		fill(hsb360(ratio * 360+delta * 2, 100, 100));
		textFont("Times New Roman", 8);
		text("Taro Sanuki", 10, 38);

		fill(hsb360(ratio * 360+delta * 3, 100, 100));
		textFont("Times New Roman", 5);
		text("Fac. of Eng. and Design, Kagawa Univ.", 10, 46);

		fill(hsb360(ratio * 360+delta * 4, 100, 100));
		textFont("Courier New", 5);
		text("sanuki.taro@kagawa-u.ac.jp", 10, 52);

		fillOpacity(0.2);
		for (t = 0; t < 80; t += 10) {
			double y = randomInRange(5, 55);                 // ★　棒の高さの範囲
			fill(hsb360((ratio * 360) + (t * 15), t * 5, t * 10));
			rect(t + 10, y, 10, 60 - y);
		}
	}

	public static void main(String[] args) {
		int i, j, n = 0;
		double x;

		a4Portrait();                           // 紙のサイズと縦横の指定 
		start();
		init();

		// ★　以下の３つのうち、どれか一つを選ぶ
//		CardSpec(14, 11, 91, 55, 2, 5);         // A-one F10A4-1 フォーマット
//		CardSpec(18.6, 21.2, 86.4, 50.8, 2, 5); // A-one F10A4-2 フォーマット
		CardSpec(8, 10.5, 97, 69, 2, 4);        // A-one F8A4-5  フォーマット

		// 繰返しで各カードを描く （通常変更しない）
		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();
	}
}
