/*
This code is released into the public domain at zero cost and with no warrenty to its quaility or usability.
use and abuse as you see fit.

	Rotation 02

	rednuht jumpstation.co.uk 2006

	Draws a circle with lines, one degree at a time, showing the problems with this tecnic resulting in holes.
	From http://www.jumpstation.co.uk/rotation/
*/
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.Color.*;
import java.awt.event.*;


public class rotation02 extends Applet implements Runnable 
{

	Thread sequence = null;
	int speed = 50;


	static int width = 162;
	static int height = 162;
	static boolean clear;
	static double angle = 0;
	static double x = 80;
	static double y = 80;
	static double r = 70;
	


	public void init()
	{
		clear=true;		
	}	

	public void drawPixel(Graphics g, int x, int y) {
		g.drawLine(x, y, x, y);
	}

	public void update (Graphics g)
	{ paint(g); }

	public void paint(Graphics g) {
		double rangle,xa,ya;
		if (clear==true) {
			g.setColor(new Color(255,255,255));
			g.fillRect(0,0,width,height);
			g.setColor(new Color(0,0,0));
			g.drawRect(5,5,width-10,height-10);
			g.setColor(new Color(255,0,0));
			drawPixel(g,(int)x,(int)y);
			clear=false;
		}
		g.setColor(new Color(255,0,0));
		rangle = angle * Math.PI /180D;
		xa = Math.cos(rangle) * r + x;
		ya = Math.sin(rangle) * r + y;
		drawPixel(g,(int)xa, (int)ya);
		g.drawLine((int)x,(int)y,(int)xa, (int)ya);
		angle=angle +1;
		if (angle>360) { 
			angle=angle-360; 
			clear=true;
		}

		
	}


   	public void run() {
      	while (true) { // infinite cycle
 			try {Thread.sleep(speed);} catch (InterruptedException e){}
			repaint();
		}
   	}

   	public void start() {
     		if(sequence==null) {
        		sequence=new Thread(this);
        		sequence.start();
     		}	
   	}

   	public void stop() { 
   		sequence = null;
   	}


}
