package sample.svg;
import static util.SVGUtil.*;

public class Parametric {
	private static final int charRange[][] = {
		{ 0x1f425, 0x1f425 },
		{ 0x1f427, 0x1f428 },
		{ 0x1f42d, 0x1f432 },
		{ 0x1f434, 0x1f43c },
	};
	
	private static int current = 0;
	private static final int nRanges = charRange.length;
	private static int c = -1;

	private 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 final static int M = 6;

	private static double fx(double t) {  /* -1 〜 1 の範囲 */
		return t*Math.cos(M*2*PI*t);
	}

	private static double fy(double t) {  /* -1 〜 1 の範囲 */
		return t*Math.sin(M*2*PI*t);
	}

//	private static double dx(double t) {  /* fx の微分 */
//		return -M*2*PI*t*Math.sin(M*2*PI*t)+Math.cos(M*2*PI*t);
//	}
//
//	private static double dy(double t) {  /* fy の微分 */
//		return M*2*PI*t*Math.cos(M*2*PI*t)+Math.sin(M*2*PI*t);
//	}

	public static void main(String[] args) {
		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();
	}
}
