package sample.svg;

import static util.SVGUtil.*;

public class CharImage {
    private static int current = 0;
    private final static int charRange[][] = {
        { 0x1f638, 0x1f640 },   
    };
    private final static int nRanges = charRange.length;
    private static int c = -1;
	
	private final static int nextChar() {
	    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;
	}

	private static int calcColor(double x, double y) { /* x, y は -1 〜 1 の範囲と仮定する */
	    double d = 2 * Math.PI * sqrt(x*x+y*y);
	    double x1 = x * cos(d) - y * sin(d);
	    double y1 = x * sin(d) + y * cos(d);
	    double b = x1/1.41421356 * 0.5 + 0.5;
	    double g = 1-b;
	    double r = y1/1.41421356 * 0.5 + 0.5;
	    return rgb1(r, g, b);
	}

	public static void main(String[] args) {
	    int i, j;
	    int num = 16;         /* 文字数 -- 2 の倍数 */
	    double x0 = centerX(), y0 = centerY();
	    double fontSize = 9;  /* フォントサイズ */

	    start();
	    rulers();
	    textFont("Arial", fontSize);            
	    for (i=0; i<num; i++) {   /* 少し中止から離れたところから始める */
	        for (j=0; j<num; j++) {
	            double x = i-(num-1)/2.0, y = j-(num-1)/2.0;
	            fill(calcColor(x/(num-1)*2, y/(num-1)*2));
	            text("&#x%x;", x0+x*fontSize, y0-y*fontSize+fontSize/2, nextChar());
	        }
	    }
	    finish();
	}
}
