Skip to content

Instantly share code, notes, and snippets.

@hanshoglund
Created September 8, 2016 17:19
Show Gist options
  • Save hanshoglund/39d652d38ab666775cd91fdbbfa326af to your computer and use it in GitHub Desktop.
Save hanshoglund/39d652d38ab666775cd91fdbbfa326af to your computer and use it in GitHub Desktop.
canvas-example.js
// State
var canvas = document.getElementById('canvas');
var c = canvas.getContext('2d');
// console.log(c)
function drawCircle(c,x,y,rad,col) {
c.beginPath();
c.arc(x,y,rad, 0, 2 * Math.PI, false);
c.fillStyle = col || 'red';
c.fill();
}
function setup () {
// c.fillCircle(50,50,50,50)
drawCircle(c, dims.x/2, dims.x/2, 5)
}
function drawFrame() {
c.clearRect(0, 0, dims.x, dims.y);
drawCircle(c, dims.x * Math.random(), dims.x * Math.random(), 5, 'green')
}
function loop() {
drawFrame()
requestAnimationFrame(loop)
}
setup()
loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment