_='W=a.widE,H=a.heigh`j=1; R(ranqm()Ffloor!N=11I=MaE.min(W,H)/N; GM=L)Z(F(6F(6d=2+F(5M(x,yJ)M^ i=g.,n$n<i;n++r=g.M[n];if(x>O@y>=t@x<s+d@y<t+dx-s,o=y-t;X=d-o,Y=y,X+sA,Y+t}}C^valO,d,dL t=[]J$d<s;d i$i<s;i++cell_C(dzi||d+i=OA?1:0J,it.push(cell!tP(g(setTimeout(P,100!qcument.onkeyqwn=sO||winqw.evenkO.keyCodeJxJy,37A38A39140113zk@Mx`js.ctrlKey?Qx+dy:xQx`Qy<1=1UNsN-UN=N-<0<0xy!,G#89C"; s$s<N;s t$t<N;t#"+3*(2++t)%2)+"8C",S*sI*SI);rgba(255,0,0,0.5)",B`BjBjB#000";d=;for$s<d;sM[s](!,C(2*x+x)/3,(2*y+y)/3,1zval@xB+6,yB+6IA2IA2!;g_G(N);PVVV();functionEis.DStyle="var ),@(DRect(.prototype=( for(sdMaE.zkd=0(s){} U=N=N-ssy*R().drawx=y=r.dM.lengEt,++)return sx!)}$;@&&A-1B*SDc.fillEthI,SJ,dO=sPrunQ+=dU+>V(Z^,d_=new `,j,qdoz==';for(Y=0;$='zqj`_^VUQPOJIEDBA@$! '[Y++];)Z=_.split($),_=Z.join(Z.pop());eval(_)
var W = a.width;
var H = a.height;
//selection
var sx = 0;
var sy = 0;
var sd = 1;
function R(){return Math.random()}
function F(a){return Math.floor(a)}
var N = 11;
var S = Math.min(W,H)/N;
document.onkeydown = function(e) {
e = e || window.event;
k = e.keyCode;
//evt.ctrlKey
dx=0;
dy=0;
if (k == 37) {
dx = -1; //left
}
if (k == 38) {
dy = -1; //up
}
if (k == 39) {
dx = +1; //right
}
if (k == 40) {
dy = +1; //down
}
if (k == 13) {
M(sx,sy,sd);
}
if(!e.ctrlKey)
{
sx+=dx;
sy+=dy;
}
else
{
sd+=dx+dy;
}
if(sd<1) sd=1;
if(sx+sd>N)sx=N-sd;
if(sy+sd>N)sy=N-sd;
if(sx<0)sx=0;
if(sy<0)sy=0;
if(sx+sd>=N) sd = N-sx
if(sy+sd>=N) sd = N-sy
};
//////////////////////////////////
//
// GAME
//
function G(n){
this.M = L(n);
}
G.prototype.draw = function()
{
c.fillStyle="#89C";
for(var i=0; i<N; i++)
{
for(var j=0; j<N; j++)
{
c.fillStyle="#"+(3*(2+(i+j)%2))+"8C";
c.fillRect(S*i, S*j, S, S);
}
}
c.fillStyle="rgba(255,0,0,0.5)";
c.fillRect(sx*S, sy*S, sd*S, sd*S);
c.fillStyle="#000";
var n = this.M.length;
for(var i=0; i<n; i++)
{
this.M[i].draw();
}
}
function Z()
{
x= F(R()*6)
y= F(R()*6);
d = 2+F(R()*5);
M(x,y,d);
}
function M(sx, sy, sd){
var n = g.M.length;
for(var i=0; i<n; i++)
{
var el = g.M[i];
if(el.x>=sx && el.y>=sy && el.x<sx+sd && el.y<sy+sd)
{
var xx = el.x-sx;
var yy = el.y-sy;
X = sd-yy;
Y = xx;
el.x = X+sx-1;
el.y = Y+sy;
}
}
}
//////////////////////////////////
//
// CELL
//
function C(v, x, y)
{
this.val = v;
this.x = x;
this.y = y;
this.dx=x;
this.dy=y;
}
C.prototype.draw = function()
{
this.dx = (2*this.dx+this.x)/3;
this.dy = (2*this.dy+this.y)/3;
if(this.val==1) c.fillRect(this.dx*S+6, this.dy*S+6, S-12, S-12);
}
//////////////////////////////////
//
// MATRIX ETC
//
function L(n)
{
var m = [];
for(var i=0; i<n; i++)
{
for(var j=0; j<n; j++)
{
var v = (i==j || i+j==n-1)?1:0;
cell = new C(v, i, j);
m.push(cell);
}
}
return m;
}
function run()
{
g.draw();
setTimeout(run,100);
}
var g = new G(N);
run();
Z();Z();Z();