Mosaic Creator extends Grid Maker
December 31st, 2007 : Nik RowellJust as promised, I have a more exciting experiment that makes use of the Grid Maker from my previous post. For those who caught the OOP reference in the title, the Mosaic Creator is actually not a subclass of the Grid Maker… although it probably should be.
After about $15 worth of Vanilla Lattes (which, sadly, is probably only 3), I’m pleased to introduce my Mosaic Creator - and AcionScript 3.0 experiment that dynamically creates a mosaic based on a few variables - photo, tile/cell size etc.
The process is quite similar to that of the Grid Maker, with a few key points:
- Create a BitmapData instance to hold the pixel data of the photo.
- In each loop through for the rows and columns, create another BitmapData object to hold a sample of the photo the size of our tiles/cells.
- Call at getAverageHex(sample:BitmapData) function, with our current sample passed as the argument. This function sums the value of each pixel in our sample and returns the average.
- Color the current tile with the average hexadecimal value we just obtained.
And that’s it! Just for fun, I’ve included the explode() function, with a slight variation: I set a random delay for for each cell to be ‘tweened/exploded.
Below is the photo being used to create the Mosaic
(Jon Stenseth in the BWCA, September 2007):












