package sample.svg;

import static util.SVGUtil.*;

public class CardSample {
	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 f10a4_1() { CardSpec(14, 11, 91, 55, 2, 5); }
//	private static void f10a4_2() { CardSpec(18.6, 21.2, 86.4, 50.8, 2, 5); }
	private static void f8a4_5()  { CardSpec(8, 10.5, 97, 69, 2, 4); }
	
	public static void main(String[] args) {
		a4Portrait();
		start();
		init();
		int i, j, n=0;
		f8a4_5();
		double 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();
	}

	private static void init() {
	}

	private static void drawCard(int n, int i, int j, double ratio) {
		drawFrame();  // for debug, comment out
		rect(0, 0, width, height);
		noStroke();
		fill(hsb360(ratio*360, 100, 100));
		textFont("MS-Mincho", 8);
		text("讃岐　花子", 10, 12);
		fill(hsb360(ratio*360+30, 100, 100));
		textFont("MS-Mincho", 6);
		text("香川大学創造工学部", 10, 20);
		fill(hsb360(ratio*360+60, 100, 100));
		textFont("Times New Roman", 8);
		fill(hsb360(ratio*360+90, 100, 100));
		text("Taro Sanuki", 10, 34);
		textFont("Times New Roman", 5);
		fill(hsb360(ratio*360+120, 100, 100));
		text("Faculty of Eng., Kagawa Univ.", 10, 40);
		fill(hsb360(ratio*360+150, 100, 100));
		textFont("Courier New", 5);
		text("sanuki@eng.kagawa-u.ac.jp", 10, 50);
		
		textFont("Arial Unicode MS", 20);
		fill(hsb360(ratio*360+180, 100, 100));
		pushMatrix();
		translate(width-20, 20);
		rotate360(ratio*360);
		translate(-10, 7.5);
		text("&#x1f43c;", 0, 0);
		popMatrix();
		
	}

	public static void drawFrame() {
		strokeWeight(0.1);
		stroke(bw1(0));
		noFill();
	}
}
