Skip to content

Instantly share code, notes, and snippets.

Created July 3, 2015 21:31
Show Gist options
  • Save anonymous/5beb571eb0f64a680444 to your computer and use it in GitHub Desktop.
Save anonymous/5beb571eb0f64a680444 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/cebobo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body onload="init();">
<script id="jsbin-javascript">
<script>
var canvas, ctx;
function init() {
// This function is called after the page is loaded
// 1 - Get the canvas
canvas = document.getElementById('myCanvas');
// 2 - Get the context
ctx=canvas.getContext('2d');
// 3 - start the animation
startAnimation();
}
var id;
function animationLoop(timeStamp) {
// 1 - Clear
ctx.clearRect(0, 0, canvas.width, canvas.height);
// 2 Draw
drawShapes(...);
// 3 Move
moveShapes(...)
// call again mainloop after XXX milliseconds
requestAnimationFrame(animationLoop);
}
function startAnimation() {
id = requestAnimationFrame(animationLoop);
}
<\/script>
</script>
<script id="jsbin-source-javascript" type="text/javascript"><script>
var canvas, ctx;
function init() {
// This function is called after the page is loaded
// 1 - Get the canvas
canvas = document.getElementById('myCanvas');
// 2 - Get the context
ctx=canvas.getContext('2d');
// 3 - start the animation
startAnimation();
}
var id;
function animationLoop(timeStamp) {
// 1 - Clear
ctx.clearRect(0, 0, canvas.width, canvas.height);
// 2 Draw
drawShapes(...);
// 3 Move
moveShapes(...)
// call again mainloop after XXX milliseconds
requestAnimationFrame(animationLoop);
}
function startAnimation() {
id = requestAnimationFrame(animationLoop);
}
<\/script></script></body>
</html>
<script>
var canvas, ctx;
function init() {
// This function is called after the page is loaded
// 1 - Get the canvas
canvas = document.getElementById('myCanvas');
// 2 - Get the context
ctx=canvas.getContext('2d');
// 3 - start the animation
startAnimation();
}
var id;
function animationLoop(timeStamp) {
// 1 - Clear
ctx.clearRect(0, 0, canvas.width, canvas.height);
// 2 Draw
drawShapes(...);
// 3 Move
moveShapes(...)
// call again mainloop after XXX milliseconds
requestAnimationFrame(animationLoop);
}
function startAnimation() {
id = requestAnimationFrame(animationLoop);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment