Inspired by some artwork consisting of overlapping circles shaded different colors I decided to write a program to generate my own interpretation. My objective was to create an aesthetic abstract picture from a source image as a mosaic where the pattern was constructed from overlapping circles. The software first takes a picture and generates a set of random circles over it. It then calculates the distinct regions defined by those various overlapping circles. For each of these regions, the underlying image is sampled to calculate the average color for that region and it is shaded as such.
Not as interesting, outlandish or labor intensive as many of my other projects, but I am really very thrilled with the results so I thought it was worth sharing. I leveraged SkiaSharp for the first time as a 2D image library and really was quite happy with it; I will continue to use for graphic experiments. The most complicated part was coming up with an efficient way to calculate the various regions defined by the space of intersecting circles in a 2d plane.
Pseudo code:
- Populate an input list containing the regions defined by the interiors of random circles
- Grab the first region on the input list
- Iterate over every other region on the input list to see if they overlap with this first region
- If I find one that intersects: calculate regions for region1 – region2, region2 – region1, and region1 U region2 and replace the two intersecting regions on the list with these sliced regions.
- If I don’t find one that intersects: then this regions doesn’t intersect with any other region, remove it from the list and add it to an output list.
- If any regions are left on the input list, then go back to #2, otherwise we are done!
- Proceed to calculate average colors and draw the resultant image using the output list of sliced regions.
Here are some iconic pictures run through my processor:
And for fun, I animated 100 generations of the same picture:
Source Code: https://github.com/rosolam/MosaicMaker