Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created September 24, 2013 23:30
Show Gist options
  • Select an option

  • Save makevoid/6692800 to your computer and use it in GitHub Desktop.

Select an option

Save makevoid/6692800 to your computer and use it in GitHub Desktop.
simple canvas animation example coded for learning
<style>
canvas {
width: 100%
}
</style>
<canvas></canvas>
<script>
// simple canvas example coded for learning
var q = document.querySelector
var canvas = document.querySelector("canvas")
var ctx = canvas.getContext('2d')
var x = 0
setInterval(
function() {
ctx.clearRect(0, 0, canvas.width, canvas.height)
x += 1
ctx.fillStyle = "#c00"
ctx.fillText("wroom", 10, 50);
ctx.fillRect(x % canvas.width, 70, 70, 30)
ctx.fillRect(x % canvas.width+65, 80, 20, 20)
ctx.fillRect(x % canvas.width+10, 95, 15, 15)
ctx.fillRect(x % canvas.width+47, 95, 15, 15)
}, 10
)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment