move: implement follow the leader algorithm

This commit is contained in:
2026-08-05 19:40:07 +02:00
parent 4ad9e76c9e
commit 63d5236924
4 changed files with 63 additions and 37 deletions
+1 -7
View File
@@ -1,5 +1,5 @@
import Vec2d from "./vec.js";
import { fillCircle, lerp, lerpRgb } from "./common.js";
import { resizeCanvas, fillCircle, lerp, lerpRgb } from "./common.js";
// constants
const SNAKE_RADIUS = 10;
@@ -27,12 +27,6 @@ let speed = 200; // px/s
let interpolation_factor = 10;
let paused = false;
function resizeCanvas(ctx: CanvasRenderingContext2D) {
ctx.canvas.width = ctx.canvas.clientWidth;
ctx.canvas.height = ctx.canvas.clientHeight;
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}
let lastTime: number | undefined = undefined;
function drawSnake(ctx: CanvasRenderingContext2D, bounds: Vec2d) {