package sample.svg;

import static util.SVGUtil.*;

public class CharLissajous {
	private final static String str[] = {
			"&#x2669;",
			"香",
			"&#x266a;",
			"川",
			"&#x266b;",
			"大",
			"&#x266c;",
			"学",
			"&#x266d;",
			"創",
			"&#x266e;",
			"造",
			"&#x266f;",
			"工",
			"&#x2654;",
			"学",
			"&#x2655;",
			"部",
	};

	private final static int numStr = str.length;
	private static int k = 0;

	private static String nextStr() {
		String ret = str[k++];
		if (k >= numStr) {
			k = 0;
		}
		return ret;
	}

	/* ここの定数を変えると形が変わる */
	private final static int A = 7;
	private final static int B = 5;
	private final static double X = PHYLLOTAXIS;

	private static double fx(double t) { /* -1 〜 1 の範囲 */
		return Math.cos(2 * A * PI * t);
	}

	private static double fy(double t) { /* -1 〜 1 の範囲 */
		return Math.sin(2 * B * PI * t + X);
	}

	private static double dx(double t) { /* fx の微分 */
		return -2 * A * PI * Math.sin(2 * A * PI * t);
	}

	private static double dy(double t) { /* fy の微分 */
		return 2 * B * PI * Math.cos(2 * B * PI * t + X);
	}

	public static void main(String[] args) {
		double x0 = centerX(), y0 = centerY();
		double fontSize = 10; /* フォントサイズ */
		int num = 256; /* 描く文字の総数 */
		int i;
		double radius = 70;

		start();
		rulers();
		textFont("Arial", fontSize);
		for (i = 0; i < num; i++) {
			double t = (double) i / num;
			double x = radius * fx(t), y = radius * fy(t);
			double angle = Math.atan2(dy(t), dx(t));
			fill(hsb1(i / 24.0 * PHI, 1, 1));
			pushMatrix();
			translate(x0 + x, y0 + y);
			rotate(angle);
			translate(-fontSize / 2, fontSize / 2);
			text(nextStr(), 0, 0);
			popMatrix();
		}
		finish();
	}
}
