views:

35

answers:

1

OK, so in my little album app (in Flash/AS3, but language doesn't matter), each page has a 5x4 grid of photos. However, some photos I want to elevate in prominence, so instead of occupying a 1x1 space, some of them would occupy a 2x2 space.

So, if I have an array of image objects that I'm iterating, in order, to fill pages sequentially...what's the best way to keep track of a) when a page is filled and b) if a 2x2 photo will fit on given point on the grid?

For example, in this case, the first four photos (marked by x's) have been placed. The fifth photo is a 2x2...it obviously can't fit in the 1st row, 5 col. position...what's a good algorithm for deciding that it needs to be placed in the next row, and that the 1x5th position is open for the next 1x1 photo?

XXXXO
OOOOO
OOOOO
OOOOO
A: 

It would probably be easier, if possible, to place the large images first, because then you can fill all remaining space with little ones.

So if you are pulling these pictures from a list, jump ahead in it until you find a large one (or two or three, however many you want), and place those. Then, jump back to where you started and fill with the unused images (skipping the large ones, obviously). To keep track if it is all filled, you can keep a counter that counts 1 for small images and 4 for the larger ones until it hits 20.

Nate B
It would be easier but i'd like a mix of small and large images on each grid...A counter is one part of the solution, but what data structure/design should I use to figure out that a spatial location in the grid would/wouldn't accomodate a large image?
Dourian
I understand that you want a mix, I meant that you should run through that routine each time a grid is shown. So if you take a blank grid, then place, say two large images, you don't have to worry about determining if they have room, you know they do. So at that point you can simply fill it up with 1x1 images. To figure out where to place the big ones, you could actually come up with a few pre-determined arrangements (like 1,1 and 4,4 being the top left corner of the big ones), since there aren't really very many possibilities.
Nate B