Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yitonghe00/7610a66374aa78edfea97f9a39feb9fe to your computer and use it in GitHub Desktop.
Save yitonghe00/7610a66374aa78edfea97f9a39feb9fe to your computer and use it in GitHub Desktop.
<style>body { min-height: 200px }</style>
<img src="img/cat.png" id="cat" style="position: absolute">
<img src="img/hat.png" id="hat" style="position: absolute">
<script>
let cat = document.querySelector("#cat");
let hat = document.querySelector("#hat");
let angle = 0;
let lastTime = null;
function animate(time) {
if (lastTime != null) angle += (time - lastTime) * 0.001;
lastTime = time;
cat.style.top = (Math.sin(angle) * 40 + 40) + "px";
cat.style.left = (Math.cos(angle) * 200 + 230) + "px";
hat.style.top = (Math.sin(angle + Math.PI) * 40 + 40) + "px";
hat.style.left = (Math.cos(angle + Math.PI) * 200 + 230) + "px";
// Your extensions here.
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment