Life in the Stencil Buffer

Stumbling through a load of OpenGL documentation I came across a demonstration of Conway’s Game of Life using the stencil buffer, which is simultaneously awesome and horrible:

Life in the Stencil Buffer

One way to create this game using OpenGL is to use a multipass algorithm. Keep the data in the color buffer, one pixel for each grid point. Assume that black (all zeros) is the background color, and the color of a live pixel is nonzero. Initialize by clearing the depth and stencil buffers to zero, set the depth-buffer writemask to zero, and set the depth comparison function so that it passes on not-equal. To iterate, read the image off the screen, enable drawing into the depth buffer, and set the stencil function so that it increments whenever a depth comparison succeeds but leaves the stencil buffer unchanged otherwise. Disable drawing into the color buffer.

Next, draw the image eight times, offset one pixel in each vertical, horizontal, and diagonal direction. When you’re done, the stencil buffer contains a count of the number of live neighbors for each pixel. Enable drawing to the color buffer, set the color to the color for live cells, and set the stencil function to draw only if the value in the stencil buffer is 3 (three live neighbors). In addition, if this drawing occurs, decrement the value in the stencil buffer. Then draw a rectangle covering the image; this paints each cell that has exactly three live neighbors with the “alive” color.

At this point, the stencil buffers contain 0, 1, 2, 4, 5, 6, 7, 8, and the values under the 2’s are correct. The values under 0, 1, 4, 5, 6, 7, and 8 must be cleared to the “dead” color. Set the stencil function to draw whenever the value is not 2, and to zero the stencil values in all cases. Then draw a large polygon of the “dead” color across the entire image. You’re done.

http://www710.univ-lyon1.fr/~jciehl/Public/OpenGL_PG/ch15.html#id5553768

Scrabble

Played a game of Scrabble with Kylie the other night, broke about four hundred records:

Me – 469 / Kylie – 397 = 866 combined 0_o

Her best – 122 for squirmy.

My best – 72 for (la)ziest, 64 for fainter.

And hence we are an awesome couple.

Let’s write something I say.

Then I sit and look down to my left and wonder what to write.

Last.fm Historical Charts v2

I updated my historical charts program to allow album and track charts, make it utf8 compatible and give it a graphical overhaul too, hurrahs all round.

Same process as before – when you first create each kind of chart it’ll take a while to fetch your data, subsequent charts will be created a whole lot faster. Eventually I’ll make a script to purge the data stored for anybody who hasn’t used the program in a couple of months so keep popping back if you get fed up with the waits.

As always comments are welcome. Oh and suggestions for a better name too..

Esbjörn Svensson, I’m Glad I Knew You

Esbjörn Svensson died yesterday, he was only 44, and I always think of you when it comes to Believe, Beleft, Below. You said you loved it, I think it was the first time I really stopped to listen properly and you were right, it’s a joy, another world between the storming Did They Tell Cousteau? and the uplifting Elevation of Love – it’s the kind of music to make me want to curl up and stop everything forever, because nothing I do will match its simple perfection.

I wanted you to give it a whirl, in his memory.

Esbjörn Svensson Trio – Believe, Beleft, Below

Inside

I had fun not revising for an exam on genetic algorithms the other night, instead going through old posts from insolence.co.uk .. it’s a horrible perfumeadvertisingflashsite now, but I was pleased to find my second favourite news article in the world survives – Philippine Troops Threaten to Attack MILF Over Soldier’s Death. Fantastic choice of name.

And: Texan tries to cash $360bn cheque

The 21-year-old’s attempt to cash the money in a bank in Fort Worth failed when staff spotted the 10 zeros on the personal cheque.

LastFM Charts

I made my program to generate charts for any date range from LastFM data available to anybody a few weeks ago and it’s had a positive response, being included on build.last.fm as an interesting extra kindofthing. Though still nobody has feedback or suggestions. Maybe in itself it’s relatively complete and I should think of other, related bits and pieces. Anybody?

I’ve made it automatically updating, so you only need to add your data once the very first time you visit, and after that it’ll check whether there should be new charts available. Maybe it should only happen a few days into the week – LastFM never get the charts out on time after all..

That and I added a few extra quick links, to 3/6/12/24 months previous. No more ‘wait a month for charts to refresh’ ;-). I should totally see if I can make this into a greasemonkey script..

PHP’s strtotime function is no end of brilliance – strtotime("-6 months") and strtotime("last sunday") are genius conceptions.