/*
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 01

	rednuht jumpstation.co.uk 2006

	Draws a circle point by point, one degree at a time.
	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 rotation01 extends Applet implements Runnable
{

	Thread sequence = null;
	int speed = 50;

	int width = 162;
	int height = 162;
	boolean clear;
	double angle = 0;
	double x = 80;		// start point
	double y = 25;		//   "     "

	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;	// used to hold the angle in radians rather than degrees
		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);
			drawPixel(g,width/2,height/2);
			clear=false;
		}
		rangle = angle * Math.PI /180D;
		x = Math.cos(rangle) + x;	// cos and sin need radians not degrees
		y = Math.sin(rangle) + y;
		drawPixel(g,(int)x, (int)y);
		angle=angle +1;		// increase by one degree
		if (angle>360) { 	// our circle only has 360 degrees
			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;
   	}


}
