Created
September 8, 2016 17:19
-
-
Save hanshoglund/39d652d38ab666775cd91fdbbfa326af to your computer and use it in GitHub Desktop.
canvas-example.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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