import static util.SVGUtil.*;

public class Nagae1 {

	// 何倍で表示するか r
	// sinの係数 sc
	// cosの係数 cc
	// sinのθの係数 stc
	// cosのθの係数 ctc
	// 荒さ(255の約数であることを推奨) d
	public static void polar(double r, double sc, double cc, int stc, int ctc, int d) {
		int i;
		int unit = (0xFF / d) + 1;
		int len = 6*unit;
		// 初期値
		double lx = (1.0 + cc)*r;
		double ly = 0;
		int cr = 0xFF;
		int cg = 0x00;
		int cb = 0x00;

		for (i = 1; i <= len; i++) {
			// 極方程式
			double a = i * 2*PI / len;
			double tr = 1.0 + sc*Math.sin(a*stc) + cc*Math.cos(a*ctc);
			double nx = tr*Math.cos(a)*r;
			double ny = tr*Math.sin(a)*r;
			// 色
			stroke(rgb255(cr, cg, cb));
			// 描画
			line(lx, ly, nx, ny);
			// 座標更新
			lx = nx;
			ly = ny;
			// 色更新
			if (i % unit == 0) continue;
			switch (i / unit) {
			case 0: cg += d; break;
			case 1: cr -= d; break;
			case 2: cb += d; break;
			case 3: cg -= d; break;
			case 4: cr += d; break;
			case 5: cb -= d; break;
			}
		}
	}

	// EntryPoint
	public static void main(String[] args) {
		start();
		rulers();
		
		// 左
		pushMatrix();
		translate(centerX()-60, centerY());
		polar(30, 0.5, 0.3, 6, 24, 17);
		popMatrix();
		
		// 右
		pushMatrix();
		translate(centerX()+60, centerY());
		polar(30, 0.5, 0.3, 5, 10, 17);
		popMatrix();
		finish();
		return;
	}
}
