I am looking for a sound algorithm that would randomly place a given number of rectangles of the same size into a bigger rectangle (canvas).
I see two ways to do it:
I create internal room-like dungeons using the following method.
1) Scatter N points at random, but not within a few pixels of each other. 2) For each point in turn, expand if possible in all four directions. Cease expanding if you hit another rectangle. 3) Cease the algorithm when no rooms can expand.
The result is N rectancles with just a few rectangular small spaces.
Code is in the binary image library
https://github.com/MalcolmMcLean/binaryimagelibrary/blob/master/dungeongenerator3.c #