#include <math.h>
#include <stdio.h>
#include "svg.h"

int nextChar(void) {
    static const int charRange[][2] = {
        { 0x1f601, 0x1f610 },
        { 0x1f612, 0x1f614 },
        { 0x1f616, 0x1f616 },
        { 0x1f618, 0x1f618 },
        { 0x1f61a, 0x1f61a },
        { 0x1f61c, 0x1f61e },
        { 0x1f620, 0x1f625 },
        { 0x1f628, 0x1f62b },
        { 0x1f62d, 0x1f62d },
        { 0x1f630, 0x1f633 },
        { 0x1f635, 0x1f637 },
    };
    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;
}

int main(void) {
    double fontSize = 6;                                   /* フォントサイズ */
    int num = 20;                                          /* 描く文字の総数 */
    double angle = 100;                                    /* 曲がる角度 */
    int i, j, k=0;
        
    start();
    rulers();
    textFont("Arial", fontSize);
    penUp();
    turn(-36);
    for (i=1; i<=num; i++) {
        for (j=0; j<i; j++) {
            fill(hsb1(k++/14.14, 1, 1));
            say("&#x%x;", nextChar());
            forward(fontSize);
        }
        turn(angle);
    }
    penDown();
    finish();
    return 0;
}

