<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<canvas id="c" width=300 height=300></canvas>
<script src="app.js"></script>
</body>
</html>
// app.js
const ctx = c.getContext('2d')
const speed = 5
let t = 0
function update(ev) {
t += ev.detail.deltaTime * speed
}
function draw() {
ctx.fillStyle = 'white'
ctx.fillRect(0, 0, 300, 300)
ctx.fillStyle = 'blue'
ctx.beginPath()
ctx.arc(150, 150 + Math.sin(t)*100, 50, 0, 2 * Math.PI)
ctx.fill()
}
window.addEventListener('AnimationUpdate', update)
window.addEventListener('AnimationDraw', draw)
Live Demo: https://jsbin.com/hamisotolo/2/edit?js,output