A nice spiral made of squares.
A Pen by Louis Hoebregts on CodePen.
| <canvas id="canvas"></canvas> |
| window.requestAnimFrame = (function(){ | |
| return window.requestAnimationFrame || | |
| window.webkitRequestAnimationFrame || | |
| window.mozRequestAnimationFrame || | |
| function( callback ){ | |
| window.setTimeout(callback, 1000 / 60); | |
| }; | |
| })(); | |
| var canvas = document.getElementById('canvas'), | |
| ctx = canvas.getContext('2d'), | |
| ww = window.innerWidth, | |
| wh = window.innerHeight, | |
| g = [ww/2,wh/2], | |
| j = 0; | |
| canvas.width = ww; | |
| canvas.height = wh; | |
| ctx.fillStyle = "black"; | |
| ctx.strokeStyle = "rgba(0,0,0,.1)"; | |
| var fps = 20; | |
| function draw() { | |
| setTimeout(function() { | |
| requestAnimationFrame(draw); | |
| ctx.translate( g[0],g[1] ); | |
| ctx.rotate(Math.PI/30); | |
| ctx.translate( -g[0],-g[1] ); | |
| ctx.fillStyle="rgba(255,255,255,.1)"; | |
| ctx.strokeStyle="rgba(255,255,255,.1)"; | |
| // if(j%2==0)ctx.fillStyle="rgba(255,255,255,.1)"; | |
| // else ctx.fillStyle="rgba(0,0,0,.1)"; | |
| ctx.beginPath(); | |
| ctx.rect(g[0], g[1], j, j); | |
| ctx.stroke(); | |
| ctx.closePath(); | |
| j+=.5; | |
| }, 1000 / fps); | |
| }; | |
| draw(); |
A nice spiral made of squares.
A Pen by Louis Hoebregts on CodePen.
| html,body{ | |
| width: 100%; | |
| height: 100%; | |
| margin: 0; | |
| padding: 0; | |
| background: black; | |
| overflow: hidden; | |
| font-family: Helvetica, arial, sans-serif; | |
| } |