From 8032bdd31ac7210d182aa66d4930ecfff96ace3d Mon Sep 17 00:00:00 2001 From: Thibaud Date: Wed, 5 Aug 2026 20:05:01 +0200 Subject: [PATCH] move: fix canvas size and bad dt unit --- move.ts | 6 +++--- snake.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/move.ts b/move.ts index acd966b..cba0444 100644 --- a/move.ts +++ b/move.ts @@ -48,7 +48,7 @@ function updateFollow(ctx: CanvasRenderingContext2D, dt: number) { function updateBounce(ctx: CanvasRenderingContext2D, dt: number) { // update head pos // P_t+1 = P_t + V * t - const newPos = trail[0].add(velocity.scale(0.001*dt)); + const newPos = trail[0].add(velocity.scale(dt)); if (newPos.x > ctx.canvas.width - 100) { velocity.x *= -1; newPos.x = ctx.canvas.width - 100; } if (newPos.y > ctx.canvas.height - 100) { velocity.y *= -1; newPos.y = ctx.canvas.height - 100; } if (newPos.x < 100) { velocity.x *= -1; newPos.x = 100; } @@ -82,8 +82,8 @@ function init() { if (!canvas) throw new Error("unable to get canvas HTML element"); const ctx = canvas.getContext("2d") as CanvasRenderingContext2D | null; if (!ctx) throw new Error("unable to get canvas 2D context"); - ctx.canvas.width = ctx.canvas.clientWidth; - ctx.canvas.height = ctx.canvas.clientHeight; + ctx.canvas.width = window.innerWidth + ctx.canvas.height = window.innerHeight canvas.onmousemove = (evt) => { const {clientX, clientY} = evt; diff --git a/snake.html b/snake.html index e3e83a6..94255d0 100644 --- a/snake.html +++ b/snake.html @@ -9,7 +9,7 @@
- +