function gr(){var c,a=g.w,b=g.h;b<a?(c=Math.round(b/g.r),g.ry=Math.round(b/c),g.rx=Math.round(a/c)):(c=Math.round(a/g.r),g.rx=Math.round(a/c),g.ry=Math.round(b/c)),g.o=c,g.fb=[];for(var e=g.rx,f=g.ry,h=0;h<e;h++){g.fb[h]=[];for(var i=0;i<f;i++)g.fb[h][i]=["00","00","00"]}for(var j=Math.floor(Math.random()*(g.rx-g.s)),k=Math.floor(Math.random()*(g.ry-g.s)),l=0;l<g.s;l++)for(var m=0;m<g.s;m++)"W"===g.sh[m][l]&&(g.fb[j+l][k+m]=["FF","FF","FF"])}function dr(){for(var a=g.rx,b=g.ry,d=g.o,e=0,f=0,h=0;h<a;h++){for(var i=0;i<b;i++)c.fillStyle="#"+g.fb[h][i][0]+g.fb[h][i][1]+g.fb[h][i][2],c.fillRect(e,f,d,d),f+=d;e+=d,f=0}}function l(){g.l=setInterval(function(){gr(),dr()},g.fr)}var g={};g.w=window.innerWidth,g.h=window.innerHeight,g.r=24,g.s=8,g.fr=100,d.addEventListener("mousedown",function(a){var b=c.getImageData(a.clientX,a.clientY,1,1);0!==b.data[0]&&clearInterval(g.l)}),g.sh=["0WWWWWWW","0W0W0WW0","0WWWWW00","0WW0WW0W","00WWWW0W","WWWWWWWW","00WWWW00","0WW00WW0"],l();
var g = {};
g.w = window.innerWidth;
g.h = window.innerHeight;
g.r = 24;
g.s = 8;
g.fr = 100;
d.addEventListener('mousedown',function(e){
var iD = c.getImageData(e.clientX, e.clientY, 1, 1);
if(iD.data[0]!==0){
clearInterval(g.l);
}
});
g.sh = [
'0WWWWWWW',
'0W0W0WW0',
'0WWWWW00',
'0WW0WW0W',
'00WWWW0W',
'WWWWWWWW',
'00WWWW00',
'0WW00WW0'
];
function gr(){
var w = g.w;
var h = g.h;
var ox, oy = 0;
if(h<w){
ox = Math.round(h/g.r);
g.ry = Math.round(h/ox);
g.rx = Math.round(w/ox);
}else{
ox = Math.round(w/g.r);
g.rx = Math.round(w/ox);
g.ry = Math.round(h/ox);
}
g.o = ox;
g.fb = [];
var rx = g.rx;
var ry = g.ry;
for(var i = 0;i<rx;i++){
g.fb[i] = [];
for(var d = 0;d<ry;d++){
//qui setta il fb
g.fb[i][d] = ['00', '00', '00'];
}
}
var x = Math.floor(Math.random() * (g.rx-g.s));
var y = Math.floor(Math.random() * (g.ry-g.s));
for(var xo = 0;xo<g.s;xo++)
{
for(var yo = 0;yo<g.s;yo++)
{
if(g.sh[yo][xo] === 'W')
g.fb[x+xo][y+yo] = ['FF','FF','FF'];
}
}
}
function dr(){
var rx = g.rx;
var ry = g.ry;
var o = g.o;
var cx = 0, cy = 0;
for(var i = 0;i<rx;i++){
for(var d = 0;d<ry;d++){
c.fillStyle = "#"+g.fb[i][d][0]+g.fb[i][d][1]+g.fb[i][d][2];
c.fillRect(cx,cy,o,o);
cy += o;
}
cx += o;
cy = 0;
}
}
function l(){
g.l = setInterval(function() {
gr();
dr();
}, g.fr);
}
l();