/******************************************************************************
 *  Compilation:  javac Koch.java
 *  Execution:    java Koch N
 *  Dependencies: Turtle.java 
 *  
 *  Dessine un flocon de Von Koch de niveu N.
 *
 *  % java Koch 5
 *
 ******************************************************************************/

public class Koch {

    // Floco d'ordre n, à pas de step
    public static void koch(int n, double step, Turtle turtle) {
        if (n == 0) {
            turtle.goForward(step);
            return;
        }
        koch(n-1, step, turtle);
        turtle.turnLeft(60.0);
        koch(n-1, step, turtle);
        turtle.turnLeft(-120.0);
        koch(n-1, step, turtle);
        turtle.turnLeft(60.0);
        koch(n-1, step, turtle);
    } 
 
    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);
        double step = 1.0 / Math.pow(3.0, n); // taille des segments à dessiner
        Turtle turtle = new Turtle(0.0, 0.0, 0.0); 
        koch(n, step, turtle); 
    } 
} 
