This script draws a TURMITE which is a Turing machine which has an orientation as well as a current state and a "tape" that consists of an infinite two-dimensional grid of cells.
document.write("<html><body><div id='g' onclick='P=(P==0)?1:0' ondblclick='clearInterval(q)'></div><div id='c'></div></body></html>")
var h="<table rows=128 cols=128 cellpadding=0 cellspacing=0 style='border:1px solid;'>"
for(r=0;r<128;r++){h+="<tr>"
for(c=0;c<128;c++){h+="<td id='c"+r+'_'+c+"' height=2 width=2></td>"}
h+="</tr>"}
document.getElementById("g").innerHTML=h
var P=0
var C=0
var STT=[[[1,1,0],[1,1,1]],[[0,0,0],[0,0,1]]]
var D=[[-1,0],[0,1],[1,0],[0,-1]]
function e(N){if(N==-1)return 127
if(N==128)return 0
return N}
function p(x,y,z){var l=["black","#fff","red"]
var c="c"+x+'_'+y
document.getElementById(c).style.backgroundColor=l[z]}
var g=[]
for(var i=0;i<128;i++){g[i]=new Array()
for(var j=0;j<128;j++)
g[i][j]=0}
var X=54
var Y=94
var d=0
var s=0
function f(){if(P)return;p(X,Y,g[X][Y])
var o=STT[s][g[X][Y]]
d=(o[1]==1)?(d+1)%4:d
g[X][Y]=o[0]
s=o[2]
X=e((X+D[d][0]))
Y=e(Y+D[d][1])
p(X,Y,2)
C++
document.getElementById('c').innerHTML=C}
var q=setInterval("f();",3)
ZG9jdW1lbnQud3JpdGUoIjxodG1sPjxib2R5PjxkaXYgaWQ9J2cnIG9uY2xpY2s9J1A9KFA9PTApPzE6MCcgb25kYmxjbGljaz0nY2xlYXJJbnRlcnZhbChxKSc+PC9kaXY+PGRpdiBpZD0nYyc+PC9kaXY+PC9ib2R5PjwvaHRtbD4iKQ0KdmFyIGg9Ijx0YWJsZSByb3dzPTEyOCBjb2xzPTEyOCBjZWxscGFkZGluZz0wIGNlbGxzcGFjaW5nPTAgc3R5bGU9J2JvcmRlcjoxcHggc29saWQ7Jz4iDQpmb3Iocj0wO3I8MTI4O3IrKyl7aCs9Ijx0cj4iDQpmb3IoYz0wO2M8MTI4O2MrKyl7aCs9Ij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div><div id='c'></div></body></html>")
var h="<table rows=128 cols=128 cellpadding=0 cellspacing=0 style='border:1px solid;'>"
for(r=0;r<128;r++){
h+="<tr>"
for(c=0;c<128;c++){
h+="<td id='c"+r+'_'+c+"' height=2 width=2></td>"
}
h+="</tr>"
}
document.getElementById("g").innerHTML=h
var P=0
var C=0
var STT=[[[1,1,0],[1,1,1]],[[0,0,0],[0,0,1]]] // State Transition Table
var D=[[-1, 0],[0, 1],[1, 0],[0, -1]] // Direction Matrix
function e(N){
if(N==-1) return 127
if(N==128) return 0
return N
}
function p(x,y,z){
var l=["black","#fff","red"]
var c="c"+x+'_'+y
document.getElementById(c).style.backgroundColor=l[z]
}
// Create grid
var g=[]
for(var i=0;i<128;i++){
g[i]=new Array()
for(var j=0;j<128;j++)
g[i][j]=0
}
var X=54
var Y=94
var d=0 // Direction ant is facing
var s=0 // State
function f(){
if(P) return; // Pause rendering
p(X,Y,g[X][Y]) // color current square with actual color
var o=STT[s][g[X][Y]]
d=(o[1]==1)?(d+1)%4:d // turn right or no turn
g[X][Y]=o[0] // Change color of square
s=o[2] // change state
X=e((X+D[d][0])) // move forward 1 step
Y=e(Y+D[d][1]) // move forward 1 step
p(X,Y,2) // Plot current square in red (ant position)
C++ // Increment iteration counter
document.getElementById('c').innerHTML=C
}
var q=setInterval("f();",3)
</script>