This project programmatically packs strings of text with circles. The result is a complex, visually pleasing image made up of simple elements.
With configuration changes, the project supports drawing both PNG and SVG files. Theoretically, the SVG output could be used as input to a pen plotter.
- Render text to a mask buffer - keep track of the bounding box of the text.
- Generate a list of random circle radii, sorted from largest to smallest.
- Iterate through the list of radii and pick a random point within the text bounding box to try and place a circle of the chosen radius
- Determine if the new circle is inside the mask. This is done by checking 8 points around the circumference of the circle as well as the center. If the circle does not fit inside the mask, pick a new point and retry. There is a limit on how many retries will occur.
- Check if the new circle would overlap any already placed circles. If the circle would overlap another, pick a new point and retry. There is a limit on how many retries will occur.
- Save the new circle to a list.
- After all radii have been attempted, loop through the list of placed circles and render them.