| 1 |
<canvas id="c" width="400" height="400"/> <script>K=[[0,0],[-1,0],[0,-1],[1,0],[0,1]],d=c.getContext("2d"),R=Math.random,f="fillStyle",r="fillRect",a=b=x=y=10,v=w=k=0,t=[],l=5,T=20,onkeydown=e=>k=e.which-36,setInterval(Z=>{for(x+=K[k][0],y+=K[k][1],x=x<0?19:x>19?0:x,y=y<0?19:y>19?0:y,d[f]="#000",d[r](0,0,400,400),d[f]="red",i=0;i<t.length;i++)Y=t[i],d[r](T*Y.x,T*Y.y,T,T),Y.x==x&&Y.y==y&&(l=5);for(t.push({x:x,y:y});t[l];)t.shift();a==x&&b==y&&(a=1+~(-T*R()),b=1+~(-T*R()),l++),d[r](T*a,T*b,T,T)},75)</script> |
Комментарии