Skip to content

Instantly share code, notes, and snippets.

@desmondmorris
Created June 9, 2012 21:02
Show Gist options
  • Save desmondmorris/2902584 to your computer and use it in GitHub Desktop.
Save desmondmorris/2902584 to your computer and use it in GitHub Desktop.
Card Bounce - Desmond, Steve, Sam
<html>
<head>
<title>Canvas example</title>
<style>
body {
margin:0;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#sandbox').attr('height', window.innerHeight);
var canvas = $('#sandbox')[0], // a.k.a. document.getElementById('sandbox');
ctx = canvas.getContext('2d'),
faceLoaded = false,
face;
function draw(left, top){
var newImage = face;
ctx.drawImage(newImage, left, top);
}
face = new Image();
face.onload = function(){
faceLoaded = true;
i = j = 1;
ceiling = 450;
timer = setInterval( function(){
draw(i * 20, (Math.sin(j)*ceiling));
j++;
i++;
ceiling--;
}, 100);
};
face.src = 'http://dl.dropbox.com/u/7389297/card.png';
});
</script>
</head>
<body>
<canvas id="sandbox" width="1200">
Sorry, get a better browser.
</canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment