From 73d8b73284f7683520942d4cf3722bac3131c50f Mon Sep 17 00:00:00 2001 From: awesomeuser Date: Fri, 7 Jul 2023 21:52:13 +0000 Subject: [PATCH] pet --- index.html | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index a6b3912..07b23d0 100644 --- a/index.html +++ b/index.html @@ -78,15 +78,26 @@ var header = document.getElementById("header"); var awdog = document.getElementById("awdog"); + var intensity = 0; + function pet() { - alert("pet"); + intensity = 10; } + var prevTime = 0; + async function update(timestamp) { + let dt = (timestamp - prevTime) / 1000; + prevTime = timestamp; + // petting shake let a = Math.random() * Math.PI * 2; - let intensity = 20; awdog.style.transform = "translate(" + (Math.cos(a) * intensity) + "px, " + (Math.sin(a) * intensity) + "px)"; + if (intensity > 0) { + intensity -= 10 * dt; + } else { + intensity = 0; + } // header let t = timestamp / 500;