Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program, using recursion, that drawsthe pattern ofsquaresshown above (there are two different examples). This shape is called a fractal. Fractals are shapes that

Write a program, using recursion, that drawsthe pattern ofsquaresshown above (there are two different examples). This shape is called a fractal. Fractals are shapes that have a recursive structure. In these examples, each square has a smaller square centered around each of its four corners. Each of those squares has four smaller squares centered at each corner. This process continues recursively until the program reaches a minimum square width. To solve this problem, you will need to use two methods from the provided StdDraw.java: StdDraw.rectangle(xc,yc,hw,hh): Draws the outline of a rectangle with a centre at (xc,yc) and the given half width and half height. StdDraw.setPenColor(Color): Sets the pen colour to the given Color. To create Color objects, use Javas Color class found in java.awt.Color (you will need to import this package). Color has a constructor with three int parameters that represent the amount of red, green, and blue. The int values must be between 0 and 255. You can look up the documentation for this class online. Define a single RecursiveSquares class with two static methods: ASSIGNMENT 4: Linked lists and recursion COMP 1020 Fall 2021 Page 5 of 5 a public static void drawCornerSquares (double width, double x, double y) method that drives the recursion. The first parameter is the width of the first square. x and y represent the center of the first square. a private static drawCornerSquares(double width, double x, double y, Color c) that recursively draws the fractal. Colorsshould be randomly generated, with each of the four cornersquares drawn using the same colour. Your class should also include two class constants: one to control the rate of decrease for the width, another that defines the minimum square width. Try different values for these constants to see how they affect your fractal.

public static void main(String[] args) {

// version 1 shown in the pdf

//RecursiveSquares.drawCornerSquares(0.6, 0.5, 0.5);

//version 2 shown in the pdf (with a different decrease rate and minimum width in RecursiveSquares)

RecursiveSquares.drawCornerSquares(0.4, 0.5, 0.5);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions