October 05, 2008
Game Of Life in 3 Lines of Code

Seeing Jop Wielens' implementation of Conway's Game of Life I wondered if I might be able to figure out a way how to run the whole game entirely with Flash's bitmapData methods. It turns out that it works, and it even works pretty fast. And at its core it just needs 3 lines of code:

calculationMap.applyFilter( gameMap, rect, origin, neighbourBlur );
calculationMap.draw( gameMap, null, colorAdd, "add");
gameMap.paletteMap( calculationMap, rect, origin, zero, zero, rules );

Of course a few objects have to get initialized once, but then it's really just these 3 lines that do all the work. Here you go - click the canvas and press any key to reinitialize the canvas with random values:

View the full source and download it here.

Posted at October 05, 2008 05:33 PM | Further reading

Super!!! I remember when on my 15, I programming this game

Posted by: NewMan on October 5, 2008 06:05 PM


Posted by: blprnt on October 5, 2008 09:28 PM

Thanks for the compliments Jeremy ;-)

Posted by: Mario Klingemann on October 5, 2008 10:29 PM

Searching google for other game of life implementations I just stumbled across this solution which uses a quite similar approach as mine, but has been done almost a year ago:


And it looks like there are some other neat experiments, too.

Posted by: Mario Klingemann on October 6, 2008 12:10 AM

It reminds me the extended version of Conway's Game of Life I did more then 15 years ago (!) following a my bother project. There were resources, fights, environment and evolution (with gene propagation). It was probably my first object oriented program. The pixels were drawn directly on video memory with machine code, on a brand new VGA powered by a 286. Unfortunately that version still outperform the flash bitmapData fifteen years later, but I have to admit the output was without antialias :).

Posted by: Fabio on October 6, 2008 06:04 PM

Mmm, that's a classic.

... and I specially like the patterns that appear first when I take a new canvas

Posted by: Pixelero on October 7, 2008 01:00 PM

Hey Mario... great minds think alike! :-) I really must update my blog too - so many cool things to show.... How about doing A* with BitmapData? I think it's possible but I haven't had the time to write the code.

BTW, thanks for another inspirational talk at Flash On The Beach this year!

Posted by: Al on October 7, 2008 08:59 PM

I've implemented the game of life in haxe some weeks ago.

Posted by: tong on October 16, 2008 01:04 PM

Bitmaps method and blend modes are so powerful, glad to see another proof of this in such a clean implementation.

Posted by: Pierluigi Pesenti on October 26, 2008 09:36 AM

This is great.

I like how you set it up to easily work with any set of rules from the life lexicon. I tried out a few different variations and they all worked nicely... my favorite has always been Coral (45678/3).

Posted by: Zevan on November 12, 2008 05:51 PM
Post a comment

Email Address:



Remember info?

Thank you!

Most Visited Entries
Sketches, Works & Source Code
In Love with
Powered by
Movable Type 2.661

© Copyright Mario Klingemann

Syndicate this site:
RSS 1.0 - RSS 2.0

Quasimondo @ flickr
Quasimondo @ LinkedIn
Quasimondo @ Twitter
Quasimondo @ Facebook
Quasimondo @ MySpace
Quasimondo is a Bright
Citizen of the TRansnational Republic
My other blog in german

My family name is written Klingemann,
not Klingelmann, Klingeman, Klingaman, Kingemann,
Kindermann, Killingaman, Klingman, Klingmann, Klingonman
Klingemman, Cleangerman, Klingerman or Kleangerman

profile for Quasimondo at Stack Overflow, Q&A for professional and enthusiast programmers