#include <math.h>
#include "svg.h"

int nextChar(void) {
        static const int charRange[][2] = {
                { 0x1f425, 0x1f425 },
                { 0x1f427, 0x1f428 },
                { 0x1f42d, 0x1f432 },
                { 0x1f434, 0x1f43c },
        };
        static int current = 0;
        static int nRanges = sizeof(charRange)/(sizeof(int)*2);
        static int c = -1;
        int nextC;
        
        if (c==-1) {
                c = charRange[current][0];
        }       
        nextC = c++;
    if (c > charRange[current][1]) {
        current++;
        if (current >= nRanges) {
                    current = 0;
                }    
        c = charRange[current][0];
    }   
        
        return nextC;
}

const int M = 6;

double fx(double t) {  /* -1 〜 1 の範囲 */
    return t*cos(M*2*PI*t);
}

double fy(double t) {  /* -1 〜 1 の範囲 */
    return t*sin(M*2*PI*t);
}

double dx(double t) {  /* fx の微分 */
    return -M*2*PI*t*sin(M*2*PI*t)+cos(M*2*PI*t);
}

double dy(double t) {  /* fy の微分 */
    return M*2*PI*t*cos(M*2*PI*t)+sin(M*2*PI*t);
}

int main(void) {
    int i;
    int num = 128;   /* 文字数の目安 */
    double x0 = centerX(), y0 = centerY();
        double fontSize = 8; /* フォントサイズ */

    start();
    rulers();
    textFont("Arial", fontSize);             
    for (i=32; i<num; i++) {   /* 少し中心から離れたところから始める */
        double x = fx(i/(num-1.0));   
        double y = fy(i/(num-1.0)); 
        fill(hsb1(i/16.0, 1, 1));
        text("&#x%x;", x0+x*110, y0+75*y+fontSize/2, nextChar());  
    }
    finish();
    return 0;
}
