Lively Kernel canvas
fromhttp://pollinimini.net/blog/rectangle-packing/20
0.1100null
60.21000000000001
RectanglePacker40
60
//seelocalinitializerforrestofsourcecodevarcontainer=$morph('BoxContainer')container.submorphs.clone().invoke('remove')for(vari=0;i<100;i++){varm=Morph.makeRectangle(0,0,Math.random()*90+10,Math.random()*90+10)m.setFill(Color.random())container.addMorph(m)}container.allMorphs=container.submorphs.clone()container.demoRectanglePacker=function(n){varcontainerExtent=this.getExtent()varpacker=newNETXUS.RectanglePacker(containerExtent.x,containerExtent.y);this.submorphs.clone().invoke('remove');this.allMorphs.slice(0,n).each(function(ea){varexent=ea.getExtent();varcoords=packer.findCoords(exent.x,exent.y);if(coords){this.addMorph(ea)ea.setPosition(pt(coords.x,coords.y))}},this)}25
Wikicontroltruetrue
null75