Tag Archives: boxer

Box filler

This is a rather frivolous script I wrote to serve some sort of purpose, but I forget exactly what that purpose was. I think it may have been to create a random sitemap using images from various pages. It takes rectangular array of squares and fills it with squares (or boxes) of random sizes. Then to make it look more attractive it fills each rectangle with a picture from placekitten.

Links

Live page
GitHub repository

Challenges

Challenge: The only real challenge here is to make sure none of the squares end up more than one box.
Solution: This challenge is overcome by choosing a square at random which has not yet been used, then finding the largest possible box size starting from that square, \(n\). A random number is thrown in the range \(1,n\) to determine the box size. Each square which fits in this box has it status changed to “used”. This process is repeated until all squares are accounted for. (Resolved)

Sample output

Lots of kittens:

Putting a kitten in a box
Putting a kitten in a box