#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 t; 
	drawFrame();  // for debug, comment out
  noFill();
	noStroke();
    
	for (t = 0; t < 91; t = t + 6) {
    double h = randomInRange(10,59);
    fill(hsb360((t+1)*(i+1)*(j+1)*12,150,300));
    fillOpacity(0.5);
    rect(t+0.5, h, 6, 69-h);
  }
}

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;
}



