Given a rectangular board of height H and width W.N colors are given and each color occupies Xi percentage of area on the board.Sum of Xi's is 1.The colors on the board must be placed in rectangles.An optimal solution has the rectangles' aspect ratios as close to 1 as possible.An ideal case has the board filled only with squares.What's the best algorithm for laying out the rectangles?
Arranging the colors on the board in the most pleasing form
algorithms
You could do it like this: find the largest square place in the boardplace a square of the largest colour left to place in there, subtract this Pi by the appropriate amountrepeatYour question, however, is far from complete and unambiguousIf you want to only have one rectangle per colour, things can get a bit more complicated.(brute force, not very elegant)Factor all the areas for the colours into their prime factors, and get all possible two-element factorizations that will fit within the board. For most numbers up to reasonable amounts, this will be relatively manageable (if not, you could just scale down a factor ten, the visual result won't differ much).for each possible combination of these two-element factorizations, try to fit them into the board (most will not succeed)find the one with best ratios, weighted however you wantI can imagine a lot better approaches exist, but these might do the trick if your board is not too large, and the amount of colours is reasonable