public class Htree { // plot an H, centered on (x, y) of the given side length public static void drawH(double x, double y, double size) { double xl = x - size/2, xr = x + size/2; double yl = y - size/2, yu = y + size/2; StdDraw.line(xl, y, xr, y); StdDraw.line(xl, yl, xl, yu); StdDraw.line(xr, yl, xr, yu); } // plot an order n H-tree, centered on (x, y) of the given side length public static void draw(int n, double x, double y, double size) { if (n == 0) return; drawH(x, y, size); double xl = x - size/2, xr = x + size/2; double yl = y - size/2, yu = y + size/2; draw(n-1, xl, yl, size/2); draw(n-1, xl, yu, size/2); draw(n-1, xr, yl, size/2); draw(n-1, xr, yu, size/2); } // read in a command line parameter N and plot an order N H-tree public static void main(String[] args) { int N = 5;//Integer.parseInt(args[0]); StdDraw.setPenRadius(0.005); draw(N, .5, .5, .5); } }