Skip to content

Commit a1ef21c

Browse files
committed
cats hat
1 parent e58f853 commit a1ef21c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<style>body { min-height: 200px }</style>
2+
<img src="img/cat.png" id="cat" style="position: absolute">
3+
<img src="img/hat.png" id="hat" style="position: absolute">
4+
5+
<script>
6+
let cat = document.querySelector("#cat");
7+
let hat = document.querySelector("#hat");
8+
9+
let angle = 0;
10+
let lastTime = null;
11+
function animate(time) {
12+
if (lastTime != null) angle += (time - lastTime) * 0.001;
13+
lastTime = time;
14+
cat.style.top = (Math.sin(angle) * 40 + 40) + "px";
15+
cat.style.left = (Math.cos(angle) * 200 + 230) + "px";
16+
17+
// Your extensions here.
18+
hat.style.top = (Math.sin(angle + Math.PI) * 40 + 40) + "px";
19+
hat.style.left = (Math.cos(angle + Math.PI) * 200 + 230) + "px";
20+
21+
requestAnimationFrame(animate);
22+
}
23+
requestAnimationFrame(animate);
24+
</script>

0 commit comments

Comments
 (0)