Skip to content

Instantly share code, notes, and snippets.

@f8lrebel
Created March 28, 2015 20:11
Show Gist options
  • Save f8lrebel/58b539d7a0a40e52bbf8 to your computer and use it in GitHub Desktop.
Save f8lrebel/58b539d7a0a40e52bbf8 to your computer and use it in GitHub Desktop.
Progress slipping away
var c = document.querySelector('canvas');
var g = c.getContext('2d');
c.width = innerWidth;
c.height = innerHeight;
var TOTALRAD = innerHeight/5;
update();
function ease(pi,a,b) {
var ip = 1-pi;
return 3*ip*ip*pi*(a||0.05) +
3*ip*pi*pi*(b||0.95)+
1*pi*pi*pi;
}
function update() {
c.width= innerWidth;
g.translate(innerWidth/2, innerHeight*1/2);
g.strokeStyle = "#802020";
var DURATION = 3.5;
var LAYERS = 7;
g.lineWidth= TOTALRAD/LAYERS+0.2;
var now = (new Date().getTime()/1000)%DURATION;
g.rotate(-now*Math.PI/DURATION-0.5);
for(var i =0;i<LAYERS;i++) {
var pi = now/DURATION;
pi = ease(pi);
pi = Math.max(0,Math.min(0.999, pi+i/20));
pi = ease(pi);
pi = ease(pi);
pi = ease(pi);
pi = ease(pi);
pi = ease(pi);
pi +=1;
g.globalAlpha =0.9-i/LAYERS;
g.beginPath();
g.arc(0,0,TOTALRAD+TOTALRAD*i/LAYERS, Math.PI*pi,Math.PI*pi+Math.PI);
g.stroke();
}
requestAnimationFrame(update);
}
canvas
{
top:0px;
left:0px;
}
body
{
margin:0;
padding:0;
background-color:#252018;
box-shadow:inset 0px 0px 120px rgba(60,10,0,0.5);
overflow:hidden;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment