var f=0;function g(){var a=arguments,b=a.length;c.beginPath();c.moveTo(a[b-3],a[b-2]);for(i=0;i<b;i+=2)c.lineTo(a[i],a[i+1]);c.fillStyle=a[b-1];c.fill();c.strokeStyle="rgba(100,100,100,.15)";c.stroke();c.closePath()}
setInterval(function(){f++;c.clearRect(0,0,800,800);for(r=0;32>r;r++)for(o=0;32>o;o++){var a=30*r+480-30*o,b=30*o-480+30*r,d;d=r-16;var e=o-16;d=80+20*Math.sin(d*d/50+e*e/50+f/30);e="rgb("+(Math.floor(128*Math.sin(f/100))+128)+","+Math.floor(255-7.5*r)+","+Math.floor(255-7.5*o)+")";g(a,b,a+30,b+30,a+30,b+30-d,a,b-d,e);g(a+30,b+30,a+60,b,a+60,b-d,a+30,b-d+30,e);g(a,b-d,a+30,b-d+30,a+60,b-d,a+30,b-d-30,e)}},50);
var maxWidth = 800;
var maxHeight = 800;
var cellSide = 30;
var horizontalCells = 32;
var verticalCells = 32;
var ctx;
var grid;
var t = 0;
function getcolor(red, green, blue, opacity) {
return 'rgb('+red+','+green+','+blue+')';
}
function drawPoly(points, color) {
ctx.beginPath();
ctx.moveTo(points[points.length - 1].x, points[points.length - 1].y);
for (i = 0; i < points.length; i++) {
ctx.lineTo(points[i].x, points[i].y);
}
ctx.fillStyle = color;
ctx.fill();
ctx.strokeStyle = 'rgba(100, 100, 100, 0.15)';
ctx.stroke();
ctx.closePath();
}
function drawPoly2() {
var points = [];
for (i = 0; i < arguments.length - 1; i += 2) {
points.push({
x: arguments[i],
y: arguments[i + 1]
});
}
drawPoly(points, arguments[arguments.length - 1]);
}
function drawSquare(ctx, x, y, side, z, i, j) {
var idx = Math.floor(255-7.5*i);
var jdx = Math.floor(255-7.5*j);
var m = Math.floor(Math.sin(t/100)*128)+128;
var color =getcolor(m, idx, jdx);
drawPoly2(x, y, x + side, y + side, x + side, y + side - z, x, y - z, color);
drawPoly2(x + side, y + side, x + 2 * side, y, x + 2 * side, y - z, x + side, y - z + side, color);
drawPoly2(x, y - z, x + side, y - z + side, x + 2 * side, y - z, x + side, y - z - side, color);
}
function f(x, y, t) {
return 80 + (Math.sin(x*x/50 + y *y /50+t/30) * 20);
}
function initialize(rows, cols) {
grid = [];
for (row = 0; row < rows; row++) {
grid[row] = [];
for (col = 0; col < cols; col++) {
grid[row][col] = f(row - horizontalCells/2, col - verticalCells/2, t);
}
}
}
function run() {
t++;
ctx.clearRect(0, 0, maxWidth, maxWidth);
initialize(horizontalCells, verticalCells);
for (row = 0; row < horizontalCells; row++) {
for (col = 0; col < verticalCells; col++) {
var x = row * cellSide + 480 - col * cellSide;
var y = col * cellSide -480 + row * cellSide;
drawSquare(ctx, x, y, cellSide, grid[row][col], row, col);
}
}
}
var c = document.getElementById('c');
c.width = maxWidth;
c.height = maxHeight;
ctx = c.getContext('2d');
setInterval(function() {
run();
}, 50);