forked from xem/miniGameOfLife
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
49 lines (49 loc) · 1.56 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<meta charset=utf-8>
<a href=//github.com/xem/miniGameOfLife><img style="position:absolute;top:0;right:0;border:0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<style>
body { width: 700px; margin: 0 auto; font-family: arial; }
textarea { width: 700px; height: 130px; border: 2px solid #000; padding: 15px }
pre#code { width: 520px; text-align: left; background: #f3f3f3; border-radius: 10px; padding: 10px; }
</style>
<center>
<br>
<h1>miniGameOfLife</h1>
<b>A HTML/JS Game of Life implementation in 238b</b>
<br>Golfed by xem, subzey and aemkei
<br>
<br>
<b>Source:</b>
<br>
<a href=3.min.html>Download</a>
<br>
<br>
<pre id=code>
<body onkeyup="a=b;b=[h='<pre>'];for(i=40;i--;h+='\n')for(j=80;j
--;){k=80*i+j;d=0;for(z in e=[1,79,80,81])d+=a[k+e[z]]+a[k-e[z]]
;h+='<a onclick=innerHTML=q[b['+k+']^=1]>'+q[b[k]=3==d|a[k]&2==d
]}innerHTML=h"onload=f.onkeyup(b=q=".@") id=f>
</pre>
<br>
<br>
<b>Demo:</b>
<br>
<br>
Click to toggle a cell - press any key to iterate
<br>
<p id=f></p>
<button id=R>random</button>
<button id=P>play/pause</button>
<script>
onkeyup=function(){a=b;b=[h='<pre>'];for(i=20;i--;h+='\n')for(j=40;j--;){k=40*i+j;d=0;for(z in e=[1,39,40,41])d+=a[k+e[z]]+a[k-e[z]];h+='<a onclick=innerHTML=q[b['+k+']^=1]>'+q[b[k]=3==d|a[k]&2==d]}f.innerHTML=h}
onload=onkeyup(b=q=".@");
R.onclick=function(){for(i=800;i--;)b[i]=~~(Math.random()*2);onkeyup()}
s=0;
P.onclick=function(){if(s){clearInterval(s);s=0}else s=setInterval(onkeyup,100)}
</script>
<br>
<br>
<br>
© Maxime Euzière - 2014
<br>
<br>
</center>