import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
import java.util.*;

public class lez20070622_2 extends JPanel implements Runnable
{
	Thread t;
	double time;
	boolean acceso = false;
	int valoreCorrente = 0;
	ArrayList valoriSenoCoseno;
	int scia = 100;
	
	public lez20070622_2()
	{
		valoriSenoCoseno = new ArrayList();
		for (double angle = 0.0; angle < 360.0; angle+=0.1)
		{
			double x = Math.cos(angle/10)*200 + 200;
			double y = Math.sin(angle/10)*200 + 200;
			valoriSenoCoseno.add(new ValoreSenoCoseno(x,y,angle));
		}
		acceso = true;
		valoreCorrente = scia;
		t = new Thread(this);
		t.start();
	}
	
	public void run()
	{
		while(t != null && acceso == true)
		{
			valoreCorrente++;
			if (valoreCorrente >= valoriSenoCoseno.size()) valoreCorrente = scia;
			repaint();
			try {t.sleep(10); } catch (InterruptedException e){ System.out.println(e.toString());}
		}
	}
	
	public void paint(Graphics _s)
	{
		super.paintComponent(_s);
		Graphics2D s = (Graphics2D)_s;
		s.setColor(Color.black);
		s.fillRect(0,0,this.getWidth(),this.getHeight());
		//s.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		if (acceso)
		{
			for (int k = scia; k > 0; k--)
			{
				int indiceTemp = valoreCorrente - k;
				if ( indiceTemp < 0 ) indiceTemp = valoriSenoCoseno.size() + indiceTemp;
				ValoreSenoCoseno c = (ValoreSenoCoseno)valoriSenoCoseno.get(indiceTemp);
				s.setColor(new Color(0,255 - k*255/scia,0));
				s.drawLine(200,200,(int)c.x, (int)c.y);
				s.fillOval((int)c.x - 15, (int)c.y - 15, 30, 30);
			}
			s.setColor(Color.green);
			ValoreSenoCoseno c = (ValoreSenoCoseno)valoriSenoCoseno.get(valoreCorrente);
			//s.drawLine(200,200,(int)c.x, (int)c.y);
			s.fillOval((int)c.x - 15, (int)c.y - 15, 30, 30);
		}
		for (int h = 0; h < this.getHeight(); h++)
		{
			if ((h%2)==1)
			{
				s.setColor(Color.black);
				s.drawLine(0,h,this.getWidth(),h);
			}
		}
	}

	public static void main(String[] a){
		JFrame f = new JFrame();
		f.setTitle("asd");
		f.setSize(400,400);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.getContentPane().add(new lez20070622_2());
		f.setVisible(true);
	}
}

class ValoreSenoCoseno
{
	double x,y,angle;
	public ValoreSenoCoseno(double x, double y, double angle)
	{
		this.x = x;
		this.y = y;
		this.angle = angle;
	}
}
