import static util.Common.hsb360;
import static util.SVGUtil.*;

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

	// 調整用の枠線を描く
	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) {
		double delta = 7.5;                                 // ★　色相の変化量
		int m, angle = 35;
		
		drawFrame();                                        // ★　調整用の枠線、印刷するときは、この行をコメントアウトする。
		
		noStroke();
		
		fill(hsb360(ratio*360, 100, 100));                  // ★　色の指定
		textFont("MS-Mincho", 8);
		text("讃岐　太郎", 10, 20);
		
		fill(hsb360(ratio*360+delta, 100, 100));            // ★　色の指定
		textFont("MS-Mincho", 6);	                       
		text("さぬき　たろう", 10, 35); 

		fill(hsb360(ratio*360+delta*2, 100, 100));          // ★　色の指定
		textFont("Times New Roman", 6);
		text("Taro Sanuki", 10, 50);

		//ベジエ
		noFill();
		pushMatrix();
		translate(width * 0.7, height * 0.45);                             // 移動
		scale(0.3, 0.3);                                                  // x, y 方向に縮小
		for(m = 0; m < 40 ;m++) {
			stroke(hsb360(m * (10 + n), m * (3 + i), m * (5 + j)));       // 線の色変更
			strokeWeight(0.75);
			pushMatrix();

			rotate360((m * 27) + angle);                                  // 指定した角度分回転
			translate(5, 0);                                              // x 方向に 5 移動

			// ベジエ曲線の描写
			// (0,0) から (40,40) まで 2 つの座標を通るような曲線を引く
			bezier(0, 0, 10 + m, -10 * j - 2 * m, 
					    10 * i + 2 * m, 60 / (n + 1) - 2 * m, 40, 40);
			popMatrix();
		}

		//アイコン
		textFont("Arial Unicode MS", 20);
		fill(hsb100(ratio*100+40, 100, 100));
		translate(-10, 7.5);
		text("&#x1f383;", 0, 0);                         // ★　中心に表示する絵文字

		popMatrix();
	}

	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();
	}
}
