import java.awt.*;
   
/**The following:
 
    x= new MyTurtlemk374saj29();
    x.tunnel();
 
   draws circles within each other so that they give the illusion of
   being in a tunnel, and the hole at the end of the tunnel gets
   bigger as you get closer to the end of it. 
   
   Then, you have GOT to do this to see all spirals:
   
       x= new MyTurtlemk374saj29();
       x.movingSpiral();

*/

    public class MyTurtlemk374saj29 extends Turtle {
  

  
 /**This method draws circles within each other so that the smaller ones
  are closer together and it gives an illusion of perspective, it is for
  the tunnel method*/
 private static int rad;
 public void drawCircles(int rad){
   moveTo(250,250,0);
   int inc= 3;
   int inc2= 1;
   int k=1;
   while (k != 100){
     drawCircle(rad);
     k=k+1;
     rad=rad+rad/10;
     inc= inc + inc2;
     inc2= inc2 +1;
   }
 }
 /**This method draws 8 lines intersecting at the center 
  * it is for the tunnel method*/
 public void drawLines(){
   moveTo(0,250,0);
   putPenDown();
   move(500);
   moveTo(250,500,90);
   putPenDown();
   move(500);
   moveTo(0,0,-45);
   move(1000);
   moveTo(0,500,45);
   move(1000);  }
 
 /**This method uses the previous two methods and puts makes the circles
  get bigger or smaller to
  make it look like we're moving forwards or backwards. The circle in
  the middle is the end of the tunnel */
 public void tunnel(){
   drawLines();
   while(2==2) {
     drawCircles(rad);
     rad= rad+5;
     fillCircle(rad);
     pause(100);
     clear();
     drawLines();
     if (rad> 700)
       while ( rad > 5){
       drawCircles(rad);
       rad= rad -5 - (200/(rad*rad));
       fillCircle(rad);
       pause(100);
       clear();
       drawLines();
     }
   }
 }
 
 /**This method draws all possible spirals, pausing between each  */
 public void movingSpiral(){
   int a= 0;
   while (2== 2){
     moveTo(250,250,0);
     spiralm(500,a,5,0);
     pause(50);
     /* this clear is optional please erase the comment slashes and try it for giggles */
     clear();
     a=a+1;    }
 }

    /**the spiral function, but with the initial direction east and the initial position in the middle*/
    public void spiralm(int n, int a, int d, int sec){
        moveTo(250,250,0);
        spiral(n,a,d,sec);
    }

     /**draw n lines, adding angle a after each one, such that line one is d pixels long, line 2 is 
     * 2*d pixels long, nad line i is d*i pixels long.  Lines alternate between green, blue, and red, and there
     * is a sec microsecond pause between the drawing of each line.*/
    public void spiral(int n, int a, int d, int sec){
        int k=1;
        int x=k*d;
        while (k<=n){
            if (k%3==1) setColor(Color.green);
            if (k%3==2) setColor(Color.blue);
            if (k%3==0) setColor(Color.red);
            move(x);
            addAngle(180-a);
            k=k+1;
            x=k*d;
            pause(sec);
        }
        
    }


}

