package primitives.spaces;
import java.awt.*;
import primitives.machines.MachineException;
import primitives.geomtry.*;
public class Demo extends ConfigurationSpace{
	int j=0;
	Dimension d;
	int r;
	ExtPoint[] p;
	int stage;
	public Demo(Dimension d,int stage){
		this.d = d;
		r = Math.min(d.width,d.height)/3;
		p = new ExtPoint[6];
		p[0] = new ExtPoint(d.width/2,d.height/2);
		p[5] = new ExtPoint(d.width/2,d.height/2);
		this.stage = stage;
	}
	public void finalize() throws Throwable{
		d = null;
		p = null;
		super.finalize();
	}
	public void redraw(Graphics g){
			if (j<180) j=j+2;
			double arcLength = 180*r/j;
			int i = j/2;
			p[0].move(d.width/2,(int)(d.height/2-r+arcLength));
			p[5].move(d.width/2,(int)(d.height/2+r-arcLength));
			for(int l=0;l<2;l++){
				p[1+l] = Geomtry.getPointByVector(p[5].toCoordinate(),arcLength,((90-i)+l*j)*Math.PI/180).toPoint();
				p[3+l] = Geomtry.getPointByVector(p[0].toCoordinate(),arcLength,((270-i)+l*j)*Math.PI/180).toPoint();
			}
			if (stage==3){
				g.drawArc((int)(d.width/2-arcLength),d.height/2-r,(int)(arcLength*2),(int)(arcLength*2),90,i);
				g.drawArc((int)(d.width/2-arcLength),(int)(d.height/2+r-2*arcLength),(int)(arcLength*2),(int)(arcLength*2),270,-i);
				g.setColor(Color.yellow);
			    Geomtry.drawJoint(g,p[2]);
			//	g.fillOval(p[2].x-2,p[2].y-2,5,5);
				g.setColor(Color.magenta);
				 Geomtry.drawJoint(g,p[3]);
			//	g.fillOval(p[3].x-2,p[3].y-2,5,5);
				g.setColor(Color.black);
				g.drawLine(d.width/2,d.height/2-r,(int)(d.width/2+Math.PI*r/2),d.height/2-r);
				g.drawLine(d.width/2,d.height/2+r,(int)(d.width/2+Math.PI*r/2),d.height/2+r);
			}else{
				g.drawArc((int)(d.width/2-arcLength),d.height/2-r,(int)(arcLength*2),(int)(arcLength*2),90,-i);
				g.drawArc((int)(d.width/2-arcLength),(int)(d.height/2+r-2*arcLength),(int)(arcLength*2),(int)(arcLength*2),270,i);
				g.setColor(Color.yellow);
			//	g.fillOval(p[1].x-2,p[1].y-2,5,5);
				Geomtry.drawJoint(g,p[1]);
				g.setColor(Color.magenta);
			//	g.fillOval(p[4].x-2,p[4].y-2,5,5);
				Geomtry.drawJoint(g,p[4]);
				g.setColor(Color.black);
				g.drawArc(d.width/2-r,d.height/2-r,r*2,r*2,90,180);
			}
	}
	public void rotateJoint(double alpha) throws MachineException{}
}
		


