Skip to content

Instantly share code, notes, and snippets.

@ebhoren
Last active August 29, 2015 14:07
Show Gist options
  • Save ebhoren/5938d311ee7944c9ca93 to your computer and use it in GitHub Desktop.
Save ebhoren/5938d311ee7944c9ca93 to your computer and use it in GitHub Desktop.
Comme des bêtes- Ribbons animation 1
var canvas = document.getElementById('canvas'),
source = document.createElement('canvas'),
width = window.innerWidth,
height = window.innerHeight,
context = canvas.getContext('2d'),
path1x = 0.0,
path2x = 0.0;
function init(){
resize();
window.addEventListener('resize', resize);
window.requestAnimationFrame( render );
};
function drawRibbon(){
var c = source.getContext('2d');
c.lineWidth = 3;
c.shadowBlur = 8;
c.shadowColor = '#D00204';
c.strokeStyle = '#D00204';
c.save();
c.beginPath();
c.moveTo( width * -0.2, height * 0.5 );
c.quadraticCurveTo( width * (( -0.2 + 0.5 ) * 0.5), Math.sin(360) * 375.0 + height * 0.5, width * 0.5, height * 0.5 );
c.quadraticCurveTo( width * (( 1.0 + 0.2 - 0.5 ) * 0.5 + 0.5), Math.sin(-360) * 375.0 + height * 0.5, width * 0.2 + width, height * 0.5 );
c.stroke();
c.closePath();
};
function resize(){
width = window.innerWidth;
height = window.innerHeight;
source.width = width;
source.height = height;
canvas.width = width;
canvas.height = height;
drawRibbon();
};
function render(){
context.save();
context.clearRect(0,0,width,height);
context.drawImage(source, -width + width * path1x, 0);
context.scale(1.0, -1.0);
context.drawImage(source, -width + width * path2x, -height);
path1x += 0.01;
path2x += 0.01;
if( path1x > 1.0 ) path1x = 0.0;
if( path2x > 1.0 ) path2x = 0.0;
window.requestAnimationFrame( render );
};
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment