Game of Life with JavaScript and Canvas
Hey there! I’m back!
After a long time of silence here in this Blog, I’ll post some new stuff. This time just a little test or example from my labs. I wrote Conways Game of Life in JavaScript and rendered it on a Canvas element.
And yeha, i just like simple like this:
You can find the pages here. It’s only client-side code and not obfuscated or some thing, so feel free to take a look on the uncommented source.
Next step maybe is replace the canvas rendering with divs and dom, cuz … yeha … canvas is just too slow and maybe i’ll post this here again.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.




Nice, but you can save over 75% CPU-time if you only draw dead pixels:
var draw = function() {
ctx.clearRect(0, 0, height,width)
grid.forEach(function(row, y) {
row.forEach(function(state, x) {
if(state == STATES.LIVE) {
var draw = {
x: x*DPI,
y: y*DPI,
h: RECT_HEIGHT,
w: RECT_WIDTH
}
ctx.fillRect(draw.x,draw.y,draw.w,draw.h)
}
})
})
}
Thanks for the hint
Good clarification. I enjoy make out the print Martha