Runs a Conway's Game of Life simulation in matrix style, containing a "Gosper glider gun". Hovering over canvas revives cells
function A(e,t){if(t)C+=t;M[e*L+C]=2;return A}D=c.height=c.width=720;T=10,L=D/T,M=[],Z=[-1,0,1],R=Math.round;a.shadowBlur=2;for(i=0;i<L*L;++i)M[i]=0;C=1;A(5)(6)(5,1)(6)(5,9)(6)(7)(4,1)(8)(3,1)(9)(3,1)(9)(6,1)(4,1)(8)(5,1)(6)(7)(6,1)(3,3)(4)(5)(3,1)(4)(5)(2,1)(6)(1,2)(2)(6)(7)(4,10)(5)(4,1)(5);setInterval(function(){function e(e){a.fillStyle=a.shadowColor=e}e("#000");a.fillRect(0,0,D,D);M=M.map(function(t,n){e(t>1?(M[n]=t=1)&&"#AFA":"#0F0");t&&a.fillText(String.fromCharCode(12448+Math.random()*96),n%L*T,T*(n-n%L)/L);s=0;Z.map(function(e){Z.map(function(t){x=n%L+e;s+=x>=0&&x<L&&M[n+t*L+e]&&1||0})});return s-3?s==4&&t:t?1:2})},99);c.onmousemove=function(e){e.offsetY<D&&e.offsetX<D&&(M[R(e.offsetY/T)*L+R(e.offsetX/T)]=2)}
ZnVuY3Rpb24gQShlLHQpe2lmKHQpQys9dDtNW2UqTCtDXT0yO3JldHVybiBBfUQ9Yy5oZWlnaHQ9Yy53aWR0aD03MjA7VD0xMCxMPUQvVCxNPVtdLFo9Wy0xLDAsMV0sUj1NYXRoLnJvdW5kO2Euc2hhZG93Qmx1cj0yO2ZvcihpPTA7aTxMKkw7KytpKU1baV09MDtDPTE7QSg1KSg2KSg1LDEpKDYpKDUsOSkoNikoNykoNCwxKSg4KSgzLDEpKDkpKDMsMSkoOSkoNiwxKSg0LDEpKDgpKDUsMSkoNikoNykoNiwxKSgzLDMpKDQpKDUpKDMsMSkoNCkoNSkoMiwxKSg2KSgxLDIpKDIpKDYpKDcpKDQsMTApKDUpKDQsMSkoNSk7c2V0SW50ZXJ2YWwoZnVuY3Rpb24oKXtmdW5jdGlvbiBlKGUpe2EuZmlsbFN0eWxlPWEuc2hhZG93Q29sb3I9ZX1lKCIjMDAwIik7YS5maWxsUmVjdCgwLDAsRCxEKTtNPU0ubWFwKGZ1bmN0aW9uKHQsbil7ZSh0PjE/KE1bbl09dD0xKSYmIiNBRkEiOiIjMEYwIik7dCYmYS5maWxsVGV4dChTdHJpbmcuZnJvbUNoYXJDb2RlKDEyNDQ4K01hdGgucmFuZG9tKCkqOTYpLG4lTCpULFQqKG4tbiVMKS9MKTtzPTA7Wi5tYXAoZnVuY3Rpb24oZSl7Wi5tYXAoZnVuY3Rpb24odCl7eD1uJUwrZTtzKz14Pj0wJiZ4PEwmJk1bbit0KkwrZV0mJjF8fDB9KX0pO3JldHVybiBzLTM/cz09NCYmdDp0PzE6Mn0pfSw5OSk7Yy5vbm1vdXNlbW92ZT1mdW5jdGlvbihlKXtlLm9mZnNldFk8RCYmZS5vZmZzZXRYPEQmJihNW1IoZS5vZmZzZXRZL1QpKkwrUihlLm9mZnNldFgvVCldPTIpfQ==
D=c.height=c.width=720
T=10, //Character Size
L=D/T, //# of Characters in a dimension
M = [], //Current state
Z=[-1,0,1],
R=Math.round;
a.shadowBlur = 2;
for(i=0;i<L*L;++i)M[i]=0; //initialize everything to dead
C=1;
function A(r,c) { //Set current column and row r to alive, increment C by c if exists
if(c)C+=c;
M[r*L+C]=2;
return A;
}
//Setting up a "Gosper glider gun"
A(5)(6) //Current column = 1
(5,1)(6)
(5,9)(6)(7)
(4,1)(8)
(3,1)(9)
(3,1)(9)
(6,1)
(4,1)(8)
(5,1)(6)(7)
(6,1)
(3,3)(4)(5) //c=21
(3,1)(4)(5)
(2,1)(6)
(1,2)(2)(6)(7)
(4,10)(5)
(4,1)(5);
setInterval(function() {
//Clear canvas
function f(p){a.fillStyle = a.shadowColor = p;}
f('#000')
a.fillRect(0, 0, D, D);
M = M.map(function(v,i) { //Map current state into new state while drawing current one
f(v > 1 ? (M[i]=v=1)&&'#AFA' : "#0F0"); //if(v>1) {M[i]=v=1; f('#AFA') } else f("#0F0");
v&&a.fillText(String.fromCharCode(12448 + Math.random() * 96), i%L*T, T*(i-i%L)/L); //i%L is the column,(i-i%L)/L is the row. Draw Random matrix character at c*T,r*T
//sums the number of living cells that are neighbouring this cell including itself
s=0;
Z.map(function(p) {
Z.map(function(q) {
x=i%L+p;
s+=(x>=0 && x<L && M[i+q*L+p] && 1)||0 //1 iff the cell at i with the steps r in rows and c in columns exist and is alive(>0), 0 otherwise
})
}); //'Map' is shorter than 'forEach'
return s-3?s==4&&v: //Equals to (s==3?1:v&&s==4)?1:0 which equals to (v?s==3||s==4:s==3)?1:0; which means if I'm alive I'll stay alive if the sum of my vicinity is 3/4 (me+2/3 neighbours)
v?1:2 //changed to only return color for new cells
//or if I'm dead then exactly 3 neighbours.
//new cells are colored white
});
},99);
c.onmousemove=function(e){
e.offsetY<D && e.offsetX<D && (M[R(e.offsetY/T)*L+R(e.offsetX/T)]=2);
}