Ex12_1



import java.applet.*;
import java.awt.*;

public class Ex12_2 extends Applet {
	int x[] = {100, 200, 120, 150, 180};	// 多角形 x座標
	int y[] = {200, 200, 270, 170, 270};	// 多角形 y座標
	int pt = 5;								// 多角形 点数
	int red, grn, blu;
	int n = 60;							// 繰返し回数 & 回転数
	double angle = Math.PI / n * 4;		// 回転角 4π/n ラジアン
	
	public void init() {
		this.setSize(300, 300);				// 初期設定:画面描画サイズ
		red = 255; grn = 125; blu = 125;	// 初期設定:RGB色
	}
	
	public void paint(Graphics g) {
		for (int i=0; i < n; i++) {
			g.setColor(new Color(red,grn,blu));	// 色作成&設定
			g.drawPolygon(x, y, pt);			// 多角形描画

			for (int j=0; j < pt; j++) {	// 多角形の点数(5点)繰り返し
				x[j] = rotate_x(x[j],y[j],angle);	// x座標回転
				y[j] = rotate_y(x[j],y[j],angle);	// y座標回転(x位置は回転後なので内側に縮むように回転)
			}
			
			red -= 125/n;	// Red変更
			grn += 125/n;	// Green変更
			blu -= 125/n;	// Blue変更
		}
	}
	
	// x座標の theta回転メソッド
	private int rotate_x(int x, int y, double theta) {
		x -= 150; y -= 120;		// 回転中心位置を原点へ移動
		x = (int)(x * Math.cos(theta) - y * Math.sin(theta));	// x座標回転
		x += 150; y += 120;		// 回転中心位置を元に戻す
		return x;
	}
	
	// y座標の theta回転メソッド
	private int rotate_y(int x, int y, double theta) {
		x -= 150; y -= 120;		// 回転中心位置を原点へ移動
		y = (int)(x * Math.sin(theta) + y * Math.cos(theta));	// x座標回転
		x += 150; y += 120;		// 回転中心位置を元に戻す
		return y;
	}
}