package sample.svg;
import static util.SVGUtil.*;

public class Reflect {
    private static String str[] = {
        "&#x1f680;",
        "香",
        "&#x1f683;",
        "川", 
        "&#x1f684;",
        "大", 
        "&#x1f685;",
        "学",
        "&#x1f691;",
        "工", 
        "&#x1f692;",
        "学",
        "&#x1f699;",
        "部",
        "&#x1f69a;",
        "&#x219c;",
        "&#x1f6a2;",
        "&#x219e;",
        "&#x1f6a4;",
        "&#x21c7;",
        "&#x1f6b2;",
        "&#x21dc;",
        "&#x1f40c;",
        "&#x21e0;",
    };
    
    private static final int numStr = str.length;
    private static int k = 0;
	
	private static String nextStr() {
	    String ret = str[k++];
	    if (k >= numStr) {
	        k=0;
	    }
	    return ret;
	}

	public static void main(String[] args) {
	    double x = centerX(), y = centerY();
	 
	    double fontSize = 6;                                     /* フォントサイズ */
	    double dx = PHI * fontSize * 1.2, dy = fontSize * 1.2;  /* 初速度の x成分, y成分 */
	    double lB = 50, rB = 297-50, uB = 35, dB = 210-35;      /* 壁の座標 */
	    double angle = Math.atan2(dy, dx);
	    int num = 256;                                           /* 描く文字の総数 */
	    int i;
	        
	    start();
	    rulers();
	    textFont("Arial", fontSize);             
	    for (i=0; i<num; i++) {
	        fill(hsb1(i/24.0*PHI, 1, 1));
	        pushMatrix();
	        translate(x, y);
	        rotate(angle);
	        translate(-fontSize/2, fontSize/2);
	        text(nextStr(), 0, 0);
	        popMatrix(); 
	        x+=dx; y+=dy;
	        if (x<lB) {
	            x = 2 * lB - x;
	            dx *= -1;
	            angle = Math.atan2(dy, dx);
	        } else if (x>rB) {
	            x = 2 * rB - x;
	            dx *= -1;
	            angle = Math.atan2(dy, dx);
	        }
	                
	        if (y<uB) {
	            y = 2 * uB - y;
	            dy *= -1;
	            angle = Math.atan2(dy, dx);
	        } else if (y>dB) {
	            y = 2 * dB - y;
	            dy *= -1;
	            angle = Math.atan2(dy, dx);
	        }
	    }
	    finish();
	}
}
