PDA

View Full Version : Algorithm multiple boxes fitting together



digitalic
July 31st, 2008, 10:07 AM
Hi everbody,
I'm trying to do an AS3 info-visualization like TED's one with his news boxes: http://www.ted.com/

All the problem is to make multiple boxes, with different width and height, fit perfectly into a constraint space...

I tried to adapt jared tarbell processing code at http://www.complexification.net/gallery/machines/boxFitting/

His algorithm make one box growing until it touches an other box: he is using a getPixel method to look for a box collision, which is incompatible with a vector rendering in flash...

Any one has an idea to make such a thing in AS3 ???

LeonardoZimbres
July 31st, 2008, 10:27 AM
hum... I dont know if much is needed. If vector rendering is a problem, bitmap class is there (and I dont know much about it). But here is not the case. I dont know if I figured wrong, but math will do well for this question. Maybe you should look how tonypa build tile based games, it is not exactely what you need, but I think that will help.
http://www.tonypa.pri.ee/tbw/tut02.html

Favardin
July 31st, 2008, 11:33 AM
Depending on the effect you want to achieve you might want to try recursive space filling. I once coded this little experiment (http://moomug.com/index.php?ep=32) which does exactly that, so if this is what you are looking for I'll hint you in the right direction.

digitalic
July 31st, 2008, 11:42 AM
@Favardin: that's exactly what I am looking for, thx :) Could you tell me more on the method / algorithm you used ?

glosrfc
July 31st, 2008, 12:19 PM
http://www.levitated.net/daily/levEmotionFractal.html

Favardin
July 31st, 2008, 01:53 PM
Well, it's actually pretty simple. You write a (recursive) method with a rectangle as an input parameter which fills this area by
a) dividing it into sub-rectangles and calls itself on those
b) fills the rectangle with something (like an image).
The decision usually depends on how small the considered area is (you'll want to limit the minimal size) and its ratio (you might not have a fitting asset to fill it).