package com.torn.sample;
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;


@SuppressWarnings("serial")
public class Main_MoveCircle2 extends JFrame implements Runnable {
	/* 定数 */
	private static final int SIZE = 600;
	private static final int OFFSET = SIZE / 2;
	
	public static void main(String[] args) {
		new Thread(new Main_MoveCircle2()).start();
	}
	public Main_MoveCircle2() {
		setTitle("円運動");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(SIZE , SIZE );
		setVisible(true);
	}
	
	private static final double THETA = Math.PI / 12;
	private int t = 1;
	
	int x = 50;
	int y = 0;
	
	public void paint(Graphics g) {
//		super.paint(g);
		
		/* 座標取得 */
		int dx, dy;
		final int r = 50;
		double wt = THETA * t;
		
		dx = (int)(- r * THETA * Math.sin(wt));
		dy = (int)(  r * THETA * Math.cos(wt));
		
		x = x + dx;
		y = y + dy;
		t++;

		/* 描画 */
		g.setColor(Color.CYAN);
		g.fillOval(OFFSET + x, OFFSET + y, 12, 12);
	}

	public void run() {
		while(true) {
			repaint();
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
