Remove line 3 (not used anywhere in code).
Remove "Graphic g, " from lines 1 and 13 (will use background of world).
Remove "g, " from lines 9, 10 and 16.
Change "g." to "getBackground." in lines 8 and 15.


int x1; int y1; double angle; int depth; public void act() { drawTree(); } private void drawTree() { if (depth == 0) return; int x2 = x1 + (int) (Math.cos(Math.toRadians(angle)) * depth * 10.0); int y2 = y1 + (int) (Math.sin(Math.toRadians(angle)) * depth * 10.0); getBackground.drawLine(x1, y1, x2, y2); drawTree(x2, y2, angle - 20, depth - 1); drawTree(x2, y2, angle + 20, depth - 1); } public void paint() { getBackground.setColor(Color.BLACK); drawTree(400, 500, -90, 9); } }
int depth = 9; int len = 10; public FracTree() // "FracTree" used as class name (replace with class name) { int high = len*deep*(deep+1)/2; GreenfootImage g = new GreenfootImage(3*high/2, high); drawTree(g, 3*high/4, high-1, -90, depth); setImage(img); } private void drawTree(GreenfootImage g, int x, int y, int a, int d) { if (d == 0) return; int x2 = x+(int)(Math.cos(Math.PI*a/180)*d*len); int y2 = y+(int)(Math.sin(Math.PI*a/180)*d*len); img.drawLine(x, y, x2, y2); drawTree(img, x2, y2, a-20, d-1); drawTree(img, x2, y2, a+20, d-1); }