- Author:
- Giancarlo Bellido
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- hackerhosting.com/cgol
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/334
- Shortlink:
- https://js1k.com/334
- Blog post:
- please update here!
- Bytes:
- 815
- Chars:
- 815
- Submission
var e=eval,p="className",q=0;function c(a){a[p]=a[p]?"":"s"}(function(h){document.write('<button onclick="q++; g(this)">Start/Stop</button><style>b:hover{background:#ccc;}b{height:20px;width:20px;display:inline-block;border-radius:6px;}b.s{background:#000;}#w{width:1000px;border:1px solid black;}</style><div id="w"/>');var l=50,n=w,b="",r=function(){g=0;for(o=0;o<8;o++){if((m=b.n[o])&&m[p]){g++}}},j=function(a){return(a>=0&&a<f)?n[a]:0},d=l*40,o=d,g,m,k,f=d;while(o--){b+='<b onclick="c(this)"></b>'}n.innerHTML=b;n=n.children;while(d--){n[d].n=[j(d-l-1),j(d-l),j(d-l+1),j(d-1),j(d+1),j(d+l-1),j(d+l),j(d+l+1)]}h.s=function(a,t){n[a][p]=t};h.g=function(a){if(q%2){for(d=0,k="";d<f;d++){r(b=n[d]);if(g!=2){if(g==3){k+=b[p]?"":"s("+d+',"s");'}else{if(b[p]){k+="s("+d+',"");'}}}}e(k);setTimeout(h.g,250)}}})(this);
- Description
- Conway's Game of Life
- Base64 encoded
dmFyIGU9ZXZhbCxwPSJjbGFzc05hbWUiLHE9MDtmdW5jdGlvbiBjKGEpe2FbcF09YVtwXT8iIjoicyJ9KGZ1bmN0aW9uKGgpe2RvY3VtZW50LndyaXRlKCc8YnV0dG9uIG9uY2xpY2s9InErKzsgZyh0aGlzKSI+U3RhcnQvU3RvcDwvYnV0dG9uPjxzdHlsZT5iOmhvdmVye2JhY2tncm91bmQ6I2NjYzt9YntoZWlnaHQ6MjBweDt3aWR0aDoyMHB4O2Rpc3BsYXk6aW5saW5lLWJsb2NrO2JvcmRlci1yYWRpdXM6NnB4O31iLnN7YmFja2dyb3VuZDojMDAwO30jd3t3aWR0aDoxMDAwcHg7Ym9yZGVyOjFweCBzb2xpZCBibGFjazt9PC9zdHlsZT48ZGl2IGlkPSJ3Ii8+Jyk7dmFyIGw9NTAsbj13LGI9IiIscj1mdW5jdGlvbigpe2c9MDtmb3Iobz0wO288ODtvKyspe2lmKChtPWIubltvXSkmJm1bcF0pe2crK319fSxqPWZ1bmN0aW9uKGEpe3JldHVybihhPj0wJiZhPGYpP25bYV06MH0sZD1sKjQwLG89ZCxnLG0sayxmPWQ7d2hpbGUoby0tKXtiKz0nPGIgb25jbGljaz0iYyh0aGlzKSI+PC9iPid9bi5pbm5lckhUTUw9YjtuPW4uY2hpbGRyZW47d2hpbGUoZC0tKXtuW2RdLm49W2ooZC1sLTEpLGooZC1sKSxqKGQtbCsxKSxqKGQtMSksaihkKzEpLGooZCtsLTEpLGooZCtsKSxqKGQrbCsxKV19aC5zPWZ1bmN0aW9uKGEsdCl7blthXVtwXT10fTtoLmc9ZnVuY3Rpb24oYSl7aWYocSUyKXtmb3IoZD0wLGs9IiI7ZDxmO2QrKyl7cihiPW5bZF0pO2lmKGchPTIpe2lmKGc9PTMpe2srPWJbcF0/IiI6InMoIitkKycsInMiKTsnfWVsc2V7aWYoYltwXSl7ays9InMoIitkKycsIiIpOyd9fX19ZShrKTtzZXRUaW1lb3V0KGguZywyNTApfX19KSh0aGlzKTs=
- Original source
var e=eval,p='className',q=0;
function c (td)
{
td[p] = td[p] ? '' : 's';
}
(function(window)
{
document.write('<button onclick="q++; g(this)">Start/Stop</button><style>b:hover{background:#ccc;}b{height:20px;width:20px;display:inline-block;border-radius:6px;}b.s{background:#000;}#w{width:1000px;border:1px solid black;}</style><div id="w"/>');
var
cols = 50,
life = w, //document.getElementById('w'),
td='',
get_neighbours = function()
{
count=0;
for (a=0;a<8;a++)
if ((x=td.n[a]) && x[p])
count++;
},
getv = function(x)
{
return (x>=0 && x<len) ? life[x] : 0;
},
i=cols*40,a=i,count, x,ev,len=i;
// Generate Table
while (a--)
td += '<b onclick="c(this)"></b>';
life.innerHTML = td;
life = life.children;
while (i--)
life[i].n = [ getv(i-cols-1), getv(i-cols), getv(i-cols+1),
getv(i-1), getv(i+1), getv(i+cols-1), getv(i+cols), getv(i+cols+1)
];
window.s = function(i, s) { life[i][p]=s; }
window.g = function(button)
{
if (q%2)
{
for (i=0,ev='';i<len;i++)
{
get_neighbours(td=life[i]);
if (count!=2)
{
if (count==3) ev+= td[p] ? '' : 's('+i+',"s");';
else
if (td[p]) ev+='s('+i+',"");';
}
}
e(ev);
setTimeout(window.g, 250);
}
}
})(this)