java - Logarithmic Spiral -


so in programming class learning use draw classes. draw line , stuff , did y=mx+b line in class.

i wanted jump ahead , start doing more crazy mathematical ones!

i'm having trouble using 1 though, found on u of princeton website.

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);         (int = 0; < 10*n; i++) {             step /= decay;              turtle.goforward(step);             turtle.turnleft(angle);         }      } }   import java.awt.color;  public class turtle {     private double x, y;     // turtle @ (x, y)     private double angle;    // facing many degrees counterclockwise x-axis      // start @ (x0, y0), facing a0 degrees counterclockwise 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 given amount, 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 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);     }  } 

turtle uses class: stddraw way many lines of code me paste here.

i keep getting error when go execute spiral:

java.lang.arrayindexoutofboundsexception: 0     @ spiral.main(spiral.java:4) 

not sure why. can me out can play around this?

did specify 2 command-line arguments? looks takes number of steps , decay parameter , crash if don't specify these.

for example:

java spiral 10 1.1


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -