I need to write a java program to draw one of four recursively defined patterns.The patterns are in the attached picture. In each pattern a smaller square is drawn at each of the four corners of the next larger square. This pattern repeats again and again. It might repeat any number of times or levels. In the picture, the pattern is repeated four times or levels. If another level were asked for, then 192 very small squares would have to be drawn. The patterns differ in which squares are drawn on top of the others and thus may be hidden from view. The largest square, the one at level one, is drawn in the center of a square canvas and the length of its side is one half the length of the side of the canvas. The center of the next smaller square is always at the corner of the larger square. And the size of the next smaller square is determined by a fixed ratio R. If the smaller square has a side of length s and the next larger square has a side of length b, then R is the ratio b/s. In the picture the ratio R is about 2.2.
I need to write a java program to draw one of four recursively defined patterns.The patterns are in the attached picture.
In each pattern a smaller square is drawn at each of the four corners of the next larger square. This pattern repeats again and again. It might repeat any number of times or levels. In the picture, the pattern is repeated four times or levels. If another level were asked for, then 192 very small squares would have to be drawn. The patterns differ in which squares are drawn on top of the others and thus may be hidden from view.
The largest square, the one at level one, is drawn in the center of a square canvas and the length of its side is one half the length of the side of the canvas. The center of the next smaller square is always at the corner of the larger square. And the size of the next smaller square is determined by a fixed ratio R. If the smaller square has a side of length s and the next larger square has a side of length b, then R is the ratio b/s. In the picture the ratio R is about 2.2.
Below i have given code for the pattern:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images