Randomly divide the length into x parts
Now arbitrarily split each smaller rectangle into separate parts
Here is some ActionScript code (written in notepad, you will need to check for errors). It takes the width and height of the input rectangle and returns an array with the vertices of the divided rectangles
private function divRect(w:Number, h:Number):Array { var rw:Number=0, rh:Number=0; var wa:Array=[0], rv:Array=[]; while(rw < w) { var r:Number=Math.random() * (w-rw); wa.push(r+rw); rw+=r; } for(var i:int=1; i<wa.length; i++) { while(rh < h) { var o:Object={x: wa[i-1], x2: wa[i]}; var s:Number=Math.random() * (h-rh); oy=rh; rh+=s; o.y2=rh; rv.push(o); } } }
source share