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

public class CardDots {
	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 final static String str[] = {
	    "&#128040;", "&#128062;", "&#9829;", "&#9830;", "&#9824;", "&#9827;"
	};

	private static void drawCard(int n, int i, int j, double ratio) {
		int k, angle;
		double delta = 7.5;                                    // ★　色相の変化量
		double sizeX = 10, sizeY = 10;                           // ★　水玉の大きさ
				
		drawFrame();                                           // ★　調整用の枠線、印刷するときは、この行をコメントアウトする。

		// ★ 塗りつぶす場合（絵文字の場合を含む）、以下の2行を使用する。
		noStroke();
		fillOpacity(0.2);                                        // ★　透明度 0 ～ 1
		
		// ★ 塗りつぶさない場合、以下の3行を使用する。
		noFill();
//		strokeWeight(1);                                       // ★　線の太さ
//		strokeOpacity(0.4);                                    // ★　透明度 0 ～ 1
		
		for(k = 0; 
				k < 20;                                          // ★　個数  10 ～ 100 程度
				      k++) {
			double x, y, h;
			x = randomInRange(5 + sizeX / 2, width - 5 - sizeX / 2);
			y = randomInRange(5 + sizeY / 2, height - 5 - sizeY / 2);
			// ★　水玉の色の範囲
			h = randomInRange(0, 1);
			fill(hsb1(h, 1, 1));		                       // ★　中身を塗りつぶす場合はこの行を選択
//			stroke(hsb1(h, 1, 1));  	                       // ★　中身を塗りつぶさない場合はこの行を選択
			
// ★　円の場合、以下の1行を使用する。		
//			ellipse(x, y, sizeX, sizeY);
			
// ★　絵文字の場合、この次の行から
            pushMatrix();
			translate(x, y);
            // ★　文字を常にまっすぐ立てるときは次の２行はコメントアウト 「
			angle = (int)randomInRange(0, 359);
            rotate360(angle);
            
            translate(-sizeY / 2, sizeY / 2);
            textFont("Segoe UI Symbol", sizeY);
			text(str[(int)randomInRange(0, str.length)], 0, 0);
			popMatrix();			
// ★　絵文字の場合、この前の行までを有効にする。
		}
		
		noStroke();
		fillOpacity(1);
		
		fill(hsb360(ratio * 360, 100, 100));                     // ★　色の指定
		textFont("MS-Mincho", 8);                              // 日本語部分のフォント　MS明朝 8ポイント
		text("讃岐 太郎", 10, 20);
		
		fill(hsb360(ratio * 360 + delta * 1, 100, 100));             // ★　色の指定
		textFont("MS-Mincho", 6);                              // 日本語部分のフォント　MS明朝 6ポイント
		text("香川大学創造工学部", 10, 28);
		
		fill(hsb360(ratio * 360 + delta * 2, 100, 100));             // ★　色の指定
		textFont("Times New Roman", 8);	                       // 英字部分のフォント Times New Roman 8ポイント
		text("Taro Sanuki", 10, 38); 
		
		fill(hsb360(ratio * 360 + delta * 3, 100, 100));             // ★　色の指定
		textFont("Times New Roman", 5);	                       // 英字部分のフォント 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);
		
		// 絵文字の描画
		textFont("Arial Unicode MS", 20);  
		pushMatrix();
		translate(width - 20, 24);
		rotate360(ratio * 360);
		translate(-10, 7.5);
		text("&#128060;", 0, 0);                               // ★　&#128060; は絵文字のパンダ, 128060 の部分は変更可能
		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();
	}
}
