var size = 32; var a = [size]; for (i = 0; i < size; i++) { a[i] = [size]; for (y = 0; y < size; y++) { a[i][y] = 1; } } function display(arr) { h = ""; for (y = 0; y < size; y++) { for (x = 0; x < size; x++) { h += "<span style='background-color:rgba(255,255,255," + (arr[x][y] / 10) + ")'></span>"; if (x == size - 1) { h += "<br/>"; } } } $("#h").html(h); } function LightSource(x, y, l) { this.x = x; this.y = y; this.l = l; } var ls = []; ls.push(new LightSource(6, 6, 4)); ls.push(new LightSource(2, 2, 3)); ls.push(new LightSource(9, 9, 5)); ls.push(new LightSource(20, 14, 8)); ls.push(new LightSource(20, 19, 8)); for (z = 0; z < ls.length; z++) { for (x = 0; x < size; x++) { for (y = 0; y < size; y++) { xd = x - ls[z].x; yd = y - ls[z].y; dist = Math.sqrt(xd * xd + yd * yd); if (ls[z].l - dist > 0) { a[x][y] += ((10 - a[x][y]) / 10) * (ls[z].l - dist); } } } } display(a);?
https://gamedev.stackexchange.com/questions/23454/grid-cell-based-light-system
http://jsfiddle.net/ZmPqL/
http://jsfiddle.net/vCgeM/