JS1k

Paul Hammond, 18 August 2010

9 years ago I entered the 5k competition with a DHTML cellula autonoma based on Langton's Ant.

I was pretty proud of being able to get everything into 5k until the JS1k contest launched this month and got me wondering how much smaller I could go.

The answer is 640 bytes.

Some of the savings come from not supporting Internet Explorer and removing unneeded functionality like color schemes. Others come from using canvas instead of absolutely positioned div elements. There's also a lot of optimizations including some neat modulo arithmetic (like x+=G*(1-v)%2 and x=x<0?w-1:x%w) and a new algorithm using less data (which means less code).

You see this in context over at the js1k site, or take a look at a local copy. You can also take a look at the original uncompressed javascript source.

While you're at it take a look at the other demos, especially my favourite entry so far, Barry van Oudtshoorn's Swarm.