#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;
}
double rx=97/2, ry=58, w=85, h=85;
int color[] = { 0xff0000, 0xffa500, 0xffff00, 0x008000, 
                0x00ffff, 0x0000ff, 0x800080, 0xff0000, 
                0xffa500, 0xffff00};

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 drawRainbow(int l, double rw, double rh) {
	int k;
	drawFrame();  // for debug, comment out

  for (k=0; k<l; k++) {
    stroke(color[k]);
    strokeWeight(5);
    noFill();
    arc(rx, ry, rw, rh, PI, 2*PI);
    rw-=10;rh-=10;
  }
}

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

	a4Portrait();
	start();
	init();
	f8a4_5();

  x = startX;
	for (i=0; i<cols; i++) {
		double y = startY;
		for (j=0; j<rows; j++) {
			pushMatrix();
			translate(x, y);
			drawRainbow(l++, w, h);
			popMatrix();
			y += height;
		}
		x += width;
	}
	finish();

  return 0;
}

