title: Logarithmic Spiral
body: <p>So in my programming class we are learning to use draw classes. Basically draw a line and stuff and we did a <code>y=mx+b</code> line in class.</p>
  
  <p>I wanted to jump ahead and start doing more crazy mathematical ones!</p>
  
  <p>I'm having trouble using this one though, which I found on the U of Princeton website.</p>
  
  <pre><code>public class Spiral {
  
      public static void main(String[] args) { 
          int N         = Integer.parseInt(args[0]);     // # sides if decay = 1.0
          double decay  = Double.parseDouble(args[1]);   // decay factor
  
          double angle  = 360.0 / N;
          double step   = Math.sin(Math.toRadians(angle/2.0));
          Turtle turtle = new Turtle(0.5, 0.0, angle/2.0);
          for (int i = 0; i &lt; 10*N; i++) {
              step /= decay; 
              turtle.goForward(step);
              turtle.turnLeft(angle);
          }
  
      }
  } 
  
  import java.awt.Color;
  
  public class Turtle {
      private double x, y;     // turtle is at (x, y)
      private double angle;    // facing this many degrees counterclockwise from the x-axis
  
      // start at (x0, y0), facing a0 degrees counterclockwise from the x-axis
      public Turtle(double x0, double y0, double a0) {
          x = x0;
          y = y0;
          angle = a0;
      }
  
      // rotate orientation delta degrees counterclockwise
      public void turnLeft(double delta) {
          angle += delta;
      }
  
      // move forward the given amount, with the pen down
      public void goForward(double step) {
          double oldx = x;
          double oldy = y;
          x += step * Math.cos(Math.toRadians(angle));
          y += step * Math.sin(Math.toRadians(angle));
          StdDraw.line(oldx, oldy, x, y);
      }
  
      // pause t milliseconds
      public void pause(int t) {
          StdDraw.show(t);
      }
  
  
      public void setPenColor(Color color) {
          StdDraw.setPenColor(color);
      }
  
      public void setPenRadius(double radius) {
          StdDraw.setPenRadius(radius);
      }
  
      public void setCanvasSize(int width, int height) {
          StdDraw.setCanvasSize(width, height);
      }
  
      public void setXscale(double min, double max) {
          StdDraw.setXscale(min, max);
      }
  
      public void setYscale(double min, double max) {
          StdDraw.setYscale(min, max);
      }
  
  
      // sample client for testing
      public static void main(String[] args) {
          double x0 = 0.5;
          double y0 = 0.0;
          double a0 = 60.0;
          double step = Math.sqrt(3)/2;
          Turtle turtle  = new Turtle(x0, y0, a0);
          turtle.goForward(step);
          turtle.turnLeft(120.0);
          turtle.goForward(step);
          turtle.turnLeft(120.0);
          turtle.goForward(step);
          turtle.turnLeft(120.0);
      }
  
  }
  </code></pre>
  
  <p>Turtle uses this class: <a href="http://algs4.cs.princeton.edu/stdlib/StdDraw.java.html" rel="nofollow"><code>StdDraw</code></a> which is just way too many lines of code for me to paste here.</p>
  
  <p>I keep getting an error when I go to execute spiral:</p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 0
      at Spiral.main(Spiral.java:4)
  </code></pre>
  
  <p>Not sure why. Can anyone help me out so I can play around with this?</p>