http://ooer.com/automondrian/
Some annoying points in the code due to my host still using GD1.6 ...
<?php
srand((double)microtime()*1000000);
$output = imagecreate(400,400);
$white = imagecolorallocate($output,255,255,255);
$black = imagecolorallocate($output,0,0,0);
$fill[] = imagecolorallocate($output,255,0,0);
$fill[] = imagecolorallocate($output,255,255,0);
$fill[] = imagecolorallocate($output,0,0,255);
imagefill($output,0,0,$white);
$segments = rand(1,6);
$building = 0;
$counter = 0;
while ($building == 0) {
if ($c++ > 20 and count($block) > 0) { $building = 1; }
if (count($block) >= $segments) { $building = 1; }
$x = rand(1,39)*10;
$y = rand(1,39)*10;
$w = rand(3,10)*10;
$h = rand(3,10)*10;
$add = 0;
if (is_array($block)) {
foreach ($block as $bl) {
if ( !( ($x >=$bl['x']) and ($x <=($bl['x']+$bl['w'])) )
and !( (($x+$w)>=$bl['x']) and (($x+$w)<=($bl['x']+$bl['w'])) )
and !( ($x <=$bl['x']) and (($x+w) >=($bl['x']+$bl['w'])) )
and !( ($y >=$bl['y']) and ($y <=($bl['y']+$bl['h'])) )
and !( (($y+$h)>=$bl['y']) and (($y+$h)<=($bl['y']+$bl['h'])) )
and !( ($y <=$bl['y']) and (($y+h) >=($bl['y']+$bl['h'])) )
)
{
$add = 1;
} else {
$add = 0;
break;
}
}
} else {
$add = 1;
}
if ($add == 1) {
$block[$counter]['x'] = $x;
$block[$counter]['y'] = $y;
$block[$counter]['w'] = $w;
$block[$counter]['h'] = $h;
$counter++;
}
}
for ($counter=0;$counter<$segments;$counter++) {
if ($block[$counter]['x'] > 0 or $block[$counter]['y'] > 0) {
imagefilledrectangle($output,0,$block[$counter]['y'],400,$block[$counter]['y']+1,$black);
imagefilledrectangle($output,0,$block[$counter]['y']+$block[$counter]['h'],400,$block[$counter]['y']+$block[$counter]['h']+1,$black);
imagefilledrectangle($output,$block[$counter]['x'],0,$block[$counter]['x']+1,400,$black);
imagefilledrectangle($output,$block[$counter]['x']+$block[$counter]['w'],0,$block[$counter]['x']+$block[$counter]['w']+1,400,$black);
}
}
for ($counter=0;$counter<$segments;$counter++) {
imagefilledrectangle($output,$block[$counter]['x']+2,$block[$counter]['y']+2,$block[$counter]['x']+$block[$counter]['w']-1,$block[$counter]['y']+$block[$counter]['h']-1,$fill[rand(0,2)]);
imagerectangle($output,$block[$counter]['x']+1,$block[$counter]['y']+1,$block[$counter]['x']+$block[$counter]['w']+1,$block[$counter]['y']+$block[$counter]['h']+1,$black);
imagerectangle($output,$block[$counter]['x'],$block[$counter]['y'],$block[$counter]['x']+$block[$counter]['w'],$block[$counter]['y']+$block[$counter]['h'],$black);
}
header("Content-Type: image/png");
imagepng($output);
?>