Source for demo by Johannes Fahrenkrug.
var dr=0,mx;d=document,b=d.body,c=b.children[0];c.width=c.height=400;t=c.getContext("2d"),rs=cs=40,w=10
b.style.margin="0px"
f='function('
d.write('<div style="float:right;width:400;height:400;font-family:monospace;background:#BBB;line-height:10px" id="r"></div>');for(i=0;i<7;i++){o=['Cb|x,y|var r=x,c=y;this.f=0;this.p='+f+'){t.fillRect(c*w,r*w,w,w);this.f=1}','s||mx=[];t.fillStyle="#BBB";t.fillRect(0,0,cs*w,rs*w);t.fillStyle="#000";for(i=0;i<=rs;i++){var g=[];for(j=0;j<=cs;j++){g[j]=new Cb(i,j)}mx.push(g)}ut()','he|e|x=0,y=0;if(e.layerX){x=e.layerX;y=e.layerY}else if(e.offsetX){x=e.offsetX;y=e.offsetY}e.r=(y-y%w)/w;e.c=(x-x%w)/w','m0|e|he(e);mx[e.r][e.c].p();dr=1;','m1|e|if(dr){he(e);mx[e.r][e.c].p();ut()}','m2=m3|e|if(dr){m1(e);dr=0}','ut||h="";for(i=0;i<=rs;i++){for(j=0;j<=cs;j++){h+=mx[i][j].f?"X":" "}h+="<br>"}d.getElementById("r").innerHTML=h'][i].split('|');eval(o[0]+'='+f+o[1]+'){'+o[2]+'}')}
s()
for(i=0;i<4;i++){a='down|move|up|out'.split('|')
c.addEventListener('mouse'+a[i],eval('m'+i),0)}