Spaces:
Running
Running
Download gauge.js from Noobjay/speedtest-robot: direct link, hf CLI and curl.
- Browser
- Download file 845 Bytes
-
https://huggingface.co/spaces/Noobjay/speedtest-robot/resolve/main/gauge.js
- Command line
-
hf download hf://spaces/Noobjay/speedtest-robot/gauge.js
-
curl -L -o gauge.js https://huggingface.co/spaces/Noobjay/speedtest-robot/resolve/main/gauge.js
845 Bytes
| const canvas = document.getElementById("gauge"); | |
| const ctx = canvas.getContext("2d"); | |
| let angle = 0; | |
| let targetSpeed = 0; | |
| function drawGauge(speed) { | |
| ctx.clearRect(0, 0, canvas.width, canvas.height); | |
| ctx.beginPath(); | |
| ctx.arc(150, 150, 100, Math.PI, 2 * Math.PI); | |
| ctx.strokeStyle = "#00ffe1"; | |
| ctx.lineWidth = 15; | |
| ctx.stroke(); | |
| // Needle | |
| const angle = Math.PI + (speed / 100) * Math.PI; | |
| const x = 150 + 90 * Math.cos(angle); | |
| const y = 150 + 90 * Math.sin(angle); | |
| ctx.beginPath(); | |
| ctx.moveTo(150, 150); | |
| ctx.lineTo(x, y); | |
| ctx.strokeStyle = "#ff0040"; | |
| ctx.lineWidth = 5; | |
| ctx.stroke(); | |
| } | |
| function animateGauge(speed) { | |
| let current = 0; | |
| const interval = setInterval(() => { | |
| if (current >= speed) { | |
| clearInterval(interval); | |
| } else { | |
| current += 1; | |
| drawGauge(current); | |
| } | |
| }, 15); | |
| } | |