Javascript+Canvas implementation of Game of Life not working -


i'm having problems javascript+canvas implementation of conways game of life. cells being created fine , canvas boxed representing cells being rendered fine. somewhere along way cells seems set alive & aren't toggling. life of me can't understand what's wrong. javascript code here , implementation here. can please tell me went wrong.

************************edit************************

i think i've figured out whats wrong. i'm passing element of 2d array reallytoggle() function, -

var reallytoggle = function(a) { //code } reallytoggle(cell[i][j]); 

i think problem lies in part of code. can tell me how can pass element of array function?

so code pretty obscure , overly-complicated honest. creating grid of custom javascript function objects way over-engineering: need 2d boolean array.

problems easiest solve if thought of 2 separate problems: problem space , world space. problem space area in solve actual problem. world space problem space mapped visual outcome. separate out problem, think of problem space 2 dimensional array of booleans , world space canvas.

if clean simulation bit, here approach may help:

//have parameters can change around var cellsize = 10; var cellswide = 100; var cellshigh = 100;  //instantiate , initialize 2d array false var thegrid = new array();  (var i=0; i<cellswide; i++) {     thegrid.push(new array());     (var j=0; j<cellsheight; j++) {         thegrid[i].push(false);     } }  //attach click event canvas (assuming canvas has been dropped on page //at assigned width/height $('#simcanvas').click(function(e) {     var = math.floor((e.pagex - this.offsetleft)/cellsize);     var j = math.floor((e.pagey - this.offsettop)/cellsize);     thegrid[i][j] = !thegrid[i][j]; }); 

this more succinct way handle problem space. mapping of problem space world space bit more straight-forward, if need let me know.

cheers


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -