If you haven't already, check out my ChipKIT implementation of Conway's Game of Life because I'm not explaining all that again! In this version there are some subtle changes to it that make it more pretty to watch, although arguably more confusing to see what's going on.
Keeping Track of Age
When I was showing the Life implementation at an open day, someone at Bristol Hackspace suggested it might be interesting to see how the population was ageing and seeing where the areas of most rapid change were, and which areas had been stable for a long time. Considering the colour depth of the monitor (256 colours) I thought that an age between 0 and 7 for each dead or alive pixel would look reasonable and set about adapting the code. The only significant change to the display code is that it now uses a colour look up table to decide what 8 bit value to draw based on the byte read from the screen array. I've left the screen array with one byte per pixel, although this is inefficient as each pixel is represented by only 4 bits. The most significant of the four bits is a binary dead/alive flag, the least significant three represent how many turns the pixel has been in this state and are incremented in a saturating way each time the board is updated. This gives a set of 16 colours, the first 8 (0-7) are shades of red fading to orange which displays most recently dead to longest inactive. The next 8 (8-15) fade from green to blue representing just born to oldest alive.
In the game logic the update of the screen values based on the age of the pixel is handled in the case where the state (dead/alive) of the pixel hasn't changed. In the case it has changed then the pixel is set to dead/alive at zero age. Because the dead/alive flag bit has been moved to bit 3 of the byte, the neighbour count is now compared to a multiple of the symbolic alive value. This means that if three neighbours are alive the sum of the 3rd bits is 24 rather than just 3 but as the thresholds are multiplied by 8 then this will still work out right.
|ChipKIT UNO32 sketch||May 21, 2014, 10:08 p.m.||7.5 KB|