Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me? (H-tree fractal) An H-tree (introduced at the beginning of

ID: 655678 • Letter: C

Question

Can someone help me?

(H-tree fractal) An H-tree (introduced at the beginning of this chapter in Figure 18.1) is a fractal defined as follows: 1. Begin with a letter H. The three lines of the H are of the same length. as shown in Figure 18.la. 2. The letter H (in its sans-serif form. H) has four endpoints. Draw an H centered at each of the four endpoints to an H-tree of order 1, as shown in Figure 18.lb. These Ks are half the size of the H that contains the four endpoints. 3. Repeat Step 2 to create an H-tree of order 2, 3,.. . , and so on, as shown in Figure 18.1c-d Write a program that draws an H-tree, as shown in Figure 18.1.

Explanation / Answer

public class Htree

{

public static void main(String[] args)

{

int SIZE = 512;

Turtle.create(SIZE, SIZE);

int xCenter = SIZE / 2;

int yCenter = SIZE / 2;

int x = 4;

recursive(xCenter, yCenter, x);

}

private static void recursive(int xCenter, int yCenter, int x)

{

int x2 = x - 1;

if (x2 < 0) { return; }

int left = xCenter - xCenter / 2;

int right = xCenter + xCenter / 2;

int top = yCenter - yCenter / 2;

int bottom = yCenter + yCenter / 2;

int middle = yCenter;

Turtle.fly(right, middle);

Turtle.go(left, middle);

Turtle.fly(right, top);

Turtle.go(right, bottom);

Turtle.fly(left, top);

Turtle.go(left, bottom);

recursive(left, top, x2);

System.out.println("Done");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote