from SimpleGraphics import * from random import randrange # Draw a fractal T-square # Parameters: # x, y: the upper left corner of the region # w: the width of the region # Returns: (none) def tsquare(x, y, w): if w >= 4: # Set the color based on the position where the square is drawn to get # a more artistic look setColor(x / 2, y / 2, (x + y) / 4) # Draw a square in the middle of the current region rect(x + w/4, y+w/4 ,w/2, w/2) # Recursively draw 4 addition tsqaures tsquare(x, y, w/2) # Upper left corner tsquare(x + w/2, y, w/2) # Upper right corner tsquare(x, y + w/2, w/2) # Lower left corner tsquare(x + w/2, y + w/2, w/2) # Lower right corner # Set the window size so that it is a power of 2 for prettier results resize(512, 512) # Draw a T-square that occupies the entire window tsquare(0, 0, 512)