Created
May 12, 2022 04:31
-
-
Save yitonghe00/7610a66374aa78edfea97f9a39feb9fe to your computer and use it in GitHub Desktop.
This file contains 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
<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