import random from drawtool import DrawTool import rectangles as rect dt = DrawTool() dt.set_XY_range(0,10, 0,10) dt.set_axes_off() # Changing the seed will result in a different drawing. # Remove this line altogether will result in a different # drawing each time you run the program. random.seed(123) # How many splits to try: num_splits = 20 # These numbers decide how many pure-vertial splits, # how many pure-horizontal splits, and how many have both vert_split_prob = 0.1 horz_split_prob = 0.1 for i in range(num_splits): # Pick a random rectangle from the current list n = len(rect.bottomX) k = random.randint(0, n-1) u = random.uniform(0,1) if u < vert_split_prob: x = rect.random_vertical(k) rect.split_vertical(k, x) elif u < vert_split_prob + horz_split_prob: y = rect.random_horizontal(k) rect.split_horizontal(k, y) else: x = rect.random_vertical(k) y = rect.random_horizontal(k) rect.split_both(k, x, y) # Draw using random colors n = len(rect.bottomX) for k in range(n): r = random.uniform(0,1) g = random.uniform(0,1) b = random.uniform(0,1) dt.set_color_rgb(r, g, b) dt.draw_filled_rectangle(rect.bottomX[k], rect.bottomY[k], rect.width[k], rect.height[k]) dt.display()