Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java please Sierpinski's Triangle is a simple and famous example of a fractal image. It is built recursively from a simple set of rules,

In Java please image text in transcribed
Sierpinski's Triangle is a simple and famous example of a fractal image. It is built recursively from a simple set of rules, illustrated in Figure 2. Your task will be to create an application that illustrates a perfect Sierpinski triangle, regardless of how large the application frame is. As the user moves and resizes the application window, the triangle should be redrawn and made larger or smaller as appropriate. Your program should display a frame that is based on the size of the user's screen. The paintComponent method of the panel on which you are drawing will be called whenever the frame is resized, so that happens automagically and you don't have to worry about it. JPanels include a getHeight() and getWidth() method that you will be able to use to get the information you need for passing to a recursive draw function that you will write. The draw algorithm takes the coordinates and dimensions of a square area of the screen as input. If that square is the size of a single pixel, it should call drawRect() on the Graphics object passed into paintComponent, drawing a one-pixel square at the given coordinates. If larger, it should call the draw method three times recursively, once on the lower left quadrant of the square, once on the lower right, and once on an area centered above the other two (as illustrated in Figure 2). The solution will look a lot like Figure 3, with the largest triangle fitting into the largest square area of the frame, and the smallest triangles being three pixels in size. Sierpinski's Triangle is a simple and famous example of a fractal image. It is built recursively from a simple set of rules, illustrated in Figure 2. Your task will be to create an application that illustrates a perfect Sierpinski triangle, regardless of how large the application frame is. As the user moves and resizes the application window, the triangle should be redrawn and made larger or smaller as appropriate. Your program should display a frame that is based on the size of the user's screen. The paintComponent method of the panel on which you are drawing will be called whenever the frame is resized, so that happens automagically and you don't have to worry about it. JPanels include a getHeight() and getWidth() method that you will be able to use to get the information you need for passing to a recursive draw function that you will write. The draw algorithm takes the coordinates and dimensions of a square area of the screen as input. If that square is the size of a single pixel, it should call drawRect() on the Graphics object passed into paintComponent, drawing a one-pixel square at the given coordinates. If larger, it should call the draw method three times recursively, once on the lower left quadrant of the square, once on the lower right, and once on an area centered above the other two (as illustrated in Figure 2). The solution will look a lot like Figure 3, with the largest triangle fitting into the largest square area of the frame, and the smallest triangles being three pixels in size

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

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions

Question

5. Who should facilitate the focus group?

Answered: 1 week ago