#include "svg.h"

double startX, startY, width, height;
int cols, rows;

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

void f10a4_1(void) { CardSpec(14, 11, 91, 55, 2, 5); }
void f10a4_2(void) { CardSpec(18.6, 21.2, 86.4, 50.8, 2, 5); }
void f8a4_5(void)  { CardSpec(8, 10.5, 97, 69, 2, 4); }

void init(void) {
}

void drawFrame(void) {
	strokeWeight(0.1);
	stroke(bw1(0));
  noFill();
	rect(0, 0, width, height);
}

void drawCard(int n, int i, int j, double ratio) {
	int k, angle=24;
	double x = 0.7;

	drawFrame();  // for debug, comment out

	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));
	translate(width-20, 20);
	noFill();
	rotate(radians(ratio*angle));
	for (k=0; k<30 ;k++) {
		stroke(hsb1(k/29.0, 1, 1));
		pushMatrix();
		rotate(radians(k*angle));
		translate(k*x, 0);
		rect(-5, -5, 5, 5);
		popMatrix();
	}
}

int main(void) {
	int i, j, n=0;
	double x;

	a4Portrait();
	start();
	init();
	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();

  return 0;
}

