#include <math.h>
#include "svg.h"

const char* nextStr(void) {
    static const char *str[] = {
        "&#x1f337;",
        "香",
        "&#x1f338;",
        "川", 
        "&#x1f339;",
        "大", 
        "&#x1f33a;",
        "学", 
        "&#x1f33b;",
        "工", 
        "&#x1f33c;",
        "学", 
        "&#x1f340;",
        "部",
        "&#x1f341;",
        "&#x1f345;",
        "&#x1f347;",
        "&#x1f34a;",
        "&#x1f34c;",
        "&#x1f34d;",
        "&#x1f34e;",
        "&#x1f351;",
        "&#x1f352;",
        "&#x1f353;",
    };
    static const int numStr = sizeof(str)/sizeof(char*);
    static int k = 0;
    const char* ret = str[k++];
    if (k >= numStr) {
        k=0;
    }
    return ret;
}

double hues[] = { 0, 0.111, 0.222, 0.333, 0.5, 0.666, 0.777 }; /* これくらいが自然？ */
double maxR = 115, minR = 85;  /* 外側の虹、内側の虹の半径 */
int space = 7;  /* 文字の間隔の目安 */
int num = sizeof(hues)/sizeof(double);   /* 虹の色数 */

int main(void) {
    int i, j;
    double x0 = centerX(), y0 = centerY()*1.6;
    double fontSize = 6;    /* フォントサイズ */

    start();
    rulers();
    textFont("Arial", fontSize);             
    for (i=0; i<num; i++) {
        double r, len;
        int n; 
        r = maxR + (minR-maxR)/(num-1)*i;
        len = PI*r;
        n = len / space; 
        fill(hsb1(hues[i], 1, 1));
        for (j=0; j<=n; j++) {
            double angle = - PI +  PI * j / n;
            double x = cos(angle), y = sin(angle);
            pushMatrix();
            translate(x0+r*x, y0+r*y);
            rotate(angle+PI/2);
            translate(-fontSize/2, fontSize/2);
            text(nextStr(), 0, 0);
            popMatrix();
        } 
    }
    finish();
    return 0;
}
