Add a new class called Square to the fractaltriangles program. This class will model a square that can be subdivided and drawn. 

  • Define appropriate instance variables and a constructor for the class. 
  • Define a method that will draw the square. 
  • Define methods that will return smaller squares. There will be five such methods. 
    • Four of them will return one of the squares obtained by by dividing the big square into four equal quadrants. 
    • The fifth method will return a square whose vertices are at the centers of the four quadrants.
  • A method that recursively divides a big square into four smaller squares and then draws the square whose vertices coincide with the centers of those four quadrants.

See this article for more guidance.

Here (just for inspiration, not part of this exercise) is more of what can be done with this kind of mathematics:



Last modified: Thursday, March 29, 2018, 8:55 AM