import java.applet.*;
import java.awt.*;
import java.lang.Math;
import java.lang.Object;
public class Movcirc extends Applet {

     public class point implements Cloneable{
                 public int x;
                 public int y;

                  public Object clone(){ //begin clone
                    try{ //begin try
                        return super.clone();
                        } //end try
                         
                    catch(CloneNotSupportedException e){ // begin catch
                        return null;  //if there is a catch
                         } //end catch
                    } //end cloning structure for point
             
                 }  //end point def

     public class pair implements Cloneable{
                 
                 public point rt=new point();
                 public point lt=new point();

                  public Object clone(){ //begin clone
                    try{ //begin try
                        pair pa=(pair)super.clone();
                        pa.rt=(point)rt.clone();
                        pa.lt=(point)lt.clone();
                        return pa;
                        } catch(CloneNotSupportedException e){
                           return null;
                          }//end catch

                    } //end cloning structure for pair
  
   
           } //end pair def
    
public class Body implements Cloneable{
               
                public pair head=new pair();
                public pair diam=new pair(); 
                  public Object clone(){ //begin clone
                    try{ //begin try
                        Body bo=(Body)super.clone();
                        bo.diam=(pair)diam.clone();
                        bo.head=(pair)head.clone();
                        return bo;
                        } //end try
                    catch(CloneNotSupportedException e){
                           return null;
                          }//end catch

                    } //end cloning structure for body
  
 
                } // end Body  def

   private int i;

   private int last_x=0;
   private int last_y=0;
   private int neckHite  = 50;
   private int neckX = 75;
   private int centerx;
    private int centery=70;  
   private Color current_color=Color.black;
   private Button clear_button;
   private Button draw_button;
   public pair pa=new pair();
   public Body s=new Body();
   public Body er=new Body();
   public Body bo=new Body();


   private double pie=3.14159265359;
    private double angle; 
 


//init applet
   public void init(){

//set backgd color
    this.setBackground(Color.white);

//create a button
    clear_button=new Button("Clear");
    clear_button.setForeground(Color.black);
    clear_button.setBackground(Color.lightGray);
    this.add(clear_button);

//create a button
    draw_button=new Button("Roll");
    draw_button.setForeground(Color.black);
    draw_button.setBackground(Color.lightGray);
    this.add(draw_button);
   }
//end init applet





//user clicks button or chooses a color
     public boolean action(Event event, Object arg){

          if(event.target==clear_button){
               Graphics g=this.getGraphics();
               Rectangle r=this.bounds();
               g.setColor(this.getBackground());
               g.fillRect(r.x,r.y,r.width,r.height);
               return true;
              }
              //end clear

          // in case of click
         else if(event.target==draw_button){
               Graphics g=this.getGraphics();
               g.setColor(Color.black);

 
// begin graphics routine
    for(i=1; i < 600; i++){
     // begin for 
        
	angle = i*pie*0.02;


s.head.rt.x =neckX + i -10;
s.head.rt.y =neckHite-20;
s.head.lt.x =80;
s.head.lt.y =80;
centerx = s.head.rt.x + 40;
s.diam.rt.x =  (int)( 40*Math.cos(angle));
s.diam.rt.y =  (int) (40*Math.sin(angle));
s.diam.lt.x = centerx;
s.diam.lt.y = centery;



//begin draw circ
g.setColor(Color.black);
g.drawArc(s.head.rt.x,s.head.rt.y,s.head.lt.x,s.head.lt.y,0,360);
g.drawLine(centerx - s.diam.rt.x,centery - s.diam.rt.y,s.diam.lt.x,s.diam.lt.y);
// end draw circ

er=(Body)s.clone();

//begin pause
for(int j=1; j<600000;j++){int tempore=j;}
//end pause 


// begin erase
g.setColor(Color.white);
g.drawArc(er.head.rt.x-1,er.head.rt.y,er.head.lt.x,er.head.lt.y,0,360);
g.drawLine(centerx - s.diam.rt.x,centery - s.diam.rt.y,s.diam.lt.x,s.diam.lt.y);
// end erase  
    } 
// end for i





// end graphics routine
              
         return true;
        }
        // end draw button

           // Otherwise let the superclass handle it.
           else return super.action(event, arg);
     }
     // end action method
}
//end Applet

