Friday, February 20, 2015

Animated Htree java in a pgm



AnimatedHtree.java

public class AnimatedHtree
{
 public static void draw(int n, double x, double y, double size)
{
        if (n == 0) return;
                    double x0 = x - size/2, x1 = x + size/2;
        double y0 = y - size/2, y1 = y + size/2;

        StdDraw.line(x0,  y, x1,  y);
        StdDraw.line(x0, y0, x0, y1);
        StdDraw.line(x1, y0, x1, y1);
        StdDraw.show(1000);

                    draw(n-1, x0, y0, size/2);  
        draw(n-1, x0, y1, size/2);  
        draw(n-1, x1, y0, size/2);  
        draw(n-1, x1, y1, size/2);  
    }
               
                public static void main(String[] args)
    {
        int N = Integer.parseInt(args[0]);
        StdDraw.setPenRadius(0.005);
        draw(N, .5, .5, .5);
    }
}

No comments:

Post a Comment