import java.applet.*;
import java.awt.*;
import java.lang.Math;
import java.lang.Object;
public class Blob 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 rpoint implements Cloneable{
                 public double x;
                 public double y;
                 public double z;

                  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 rpoint def


    
public class Gsphere implements Cloneable{

  public rpoint[][] sphere=new rpoint[mesh][mesh];
  public point[][] osphere=new point[mesh][mesh];
                  public Object clone(){ //begin clone
                    try{ //begin try 
                        Gsphere s=(Gsphere)super.clone(); 
                        s.sphere=(rpoint[][])sphere.clone(); 
                        s.osphere=(point[][])osphere.clone();                                    
                        return s;
                        } //end try
                    catch(CloneNotSupportedException e){
                           return null;
                          }//end catch

                    } //end cloning structure for gsphere
  
 
                } // end Sphere  def

   public int mesh=30;
   private int i;
   private int j;
   private int xxpix;
   private int xypix;
   private int yypix;
   private int yxpix;
   private int zypix;
   private double pie=3.14159265359;
   private double dirx=15*Math.cos(pie/3);
   private double diry=15*Math.sin(pie/3);
   private int last_x=0;
   private int last_y=0;

   private Color current_color=Color.black;
   private Button clear_button;
   private Button draw_button;
   private Choice ang_choices;

   public Gsphere er =new Gsphere();
   public Gsphere cs = new Gsphere();
   public Gsphere grid =new Gsphere();

   private double radius;
   private double xmult=0.5;
   private double mult=0.01;
   private double phi=0.0;
   private double psi=0.0;
   private int delX;
   private int delY;



//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("Draw Cube");
    draw_button.setForeground(Color.black);
    draw_button.setBackground(Color.lightGray);
    this.add(draw_button);



   }
//end init applet




//called when mouse click
    public boolean mouseDown(Event e, int x, int y){
          last_x=x; last_y=y;
           return true;
       }


//called when mouse moves
    public boolean mouseDrag(Event e, int x, int y){
          Graphics g=this.getGraphics();
          er=(Gsphere)cs.clone();


// figure phi and psi
 
       delX=x - last_x;
       delY=y - last_y;

       phi=phi+ mult*delX;
      psi=psi- mult*delY;
       
 






//figure vertices



         g.setColor(Color.white);

              
//draw
        
               g.setColor(Color.black);

 

          last_x=x;
          last_y=y;
          return true;
      }

//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){

// draw
               Graphics g=this.getGraphics();
               g.setColor(Color.black);
 for(j=1;j<20;j++){
radius=3.0;
           cs.sphere[1][1].x=0.0;
         // cs.osphere[0][j].y=220;
               } //end for j init
   for(i=1;i<mesh -1;i++){
   for(j=0;j<mesh;j++){
            //cs.sphere[i][j].z= -1 + 2*i/mesh;
           // radius=25*Math.sqrt(1 - cs.sphere[i][j].z*cs.sphere[i][j].z);
            //cs.sphere[i][j].x=radius*Math.cos(2*pie*j/mesh);
           // cs.sphere[i][j].y=radius*Math.sin(2*pie*j/mesh);
           // xxpix=(int)(cs.sphere[i][j].x*dirx);
           // xypix=(int)(cs.sphere[i][j].x*diry);
           // yypix=(int)(cs.sphere[i][j].y*dirx);
           // yxpix=(int)(cs.sphere[i][j].y*diry);
           // zypix=(int)(15*cs.sphere[i][j].z);
          //  cs.osphere[i][j].x= 310 + xxpix - yxpix;
          //  cs.osphere[i][j].y= 220 + xypix + yypix -zypix;
           // g.drawLine(cs.osphere[i][j-1].x,cs.osphere[i][j-1].y,cs.osphere[i][j].x,cs.osphere[i][j].y);
                      } // end for j
                      } // end for i          
                
            
           
          return true;
          } //end draw button event
           // other wise let superclass handle it
          else return super.action(event, arg);
     }
     // end action method
}
//end Applet

