1 |
# Drawrect Module |
2 |
|
3 |
def drawrect((x1, y1), (x2, y2), plot, fillrect): |
4 |
color= plot(x1, y1) |
5 |
cut= 0 |
6 |
x, y= x1+1, y1 |
7 |
while x<=x2: |
8 |
if color<>plot(x, y): |
9 |
cut= 1 |
10 |
x= x+1 |
11 |
x, y= x2, y1+1 |
12 |
while y<=y2: |
13 |
if color<>plot(x, y): |
14 |
cut= 1 |
15 |
y= y+1 |
16 |
x, y= x2-1, y2 |
17 |
while x>=x1: |
18 |
if color<>plot(x, y): |
19 |
cut= 1 |
20 |
x= x-1 |
21 |
x, y= x1, y2-1 |
22 |
while y>y1: |
23 |
if color<>plot(x, y): |
24 |
cut= 1 |
25 |
y= y-1 |
26 |
if x2-x1<=1 or y2-y1<=1: |
27 |
return |
28 |
if cut: |
29 |
if x2-x1 > y2-y1: # If wider than high |
30 |
xc= ((x2-x1)/2)+x1 |
31 |
drawrect((x1, y1), (xc, y2), plot, fillrect) |
32 |
drawrect((xc, y1), (x2, y2), plot, fillrect) |
33 |
else: # if higher than wide |
34 |
yc= ((y2-y1)/2)+y1 |
35 |
drawrect((x1, y1), (x2, yc), plot, fillrect) |
36 |
drawrect((x1, yc), (x2, y2), plot, fillrect) |
37 |
else: |
38 |
fillrect(x1, y1, x2, y2, color) |