import java.util.*; public class TreeDraw { public static void treeDraw(int depth,double x,double xLow,double xHi,double y,double dY){ StdDraw.filledCircle(x,y,0.005); if (depth == 0) return; double xLeft = (xLow + x)/2.0; double xRight = (x + xHi)/2.0; StdDraw.line(x,y,xLeft,y+dY); StdDraw.line(x,y,xRight,y+dY); treeDraw(depth-1,xLeft,xLow,x,y+dY,dY); treeDraw(depth-1,xRight,x,xHi,y+dY,dY); } public static void main(String[] args){ String commands = "\nTreeDraw (version 2.7182)"; System.out.println(commands); Scanner sc = new Scanner(System.in); System.out.print("> "); String command = sc.next(); while (!command.equals("quit") && !command.equals("q")){ if (command.equals("help")) System.out.println(commands); if (command.equals("draw") || command.equals("d")){ StdDraw.clear(); System.out.print(">> "); int n = sc.nextInt(); treeDraw(n,0.5,0.0,1.0,1.0,-0.1); } System.out.print("> "); command = sc.next(); } System.exit(0); } }