snake: implement pause

This commit is contained in:
2026-08-05 11:11:50 +02:00
parent 75ecf670f8
commit 877137803a
2 changed files with 79 additions and 70 deletions
+5 -6
View File
@@ -15,7 +15,7 @@ export const DIRECTIONS: Point[] = [
];
export function lerp(a: Point, b: Point, p: number) {
return {
return {
x: a.x + (b.x - a.x) * p,
y: a.y + (b.y - a.y) * p
};
@@ -25,7 +25,7 @@ export function quadraticBezier(a: Point, b: Point, c: Point, res=0.05) {
const eps = 0.001; // to prevent issues with float comparaison (p <= 1)
const curve = [];
for (let p = 0; p - 1 < eps; p += res) {
const ab = lerp(a, b, p);
const ab = lerp(a, b, p);
const bc = lerp(b, c, p);
const abc = lerp(ab, bc, p);
curve.push(abc);
@@ -37,9 +37,9 @@ export function cubicBezier(a: Point, b: Point, c: Point, d: Point, res=0.05) {
const eps = 0.001; // to prevent issues with float comparaison (p <= 1)
const curve = [];
for (let p = 0; p - 1 < eps; p += res) {
const ab = lerp(a, b, p);
const bc = lerp(b, c, p);
const cd = lerp(c, d, p);
const ab = lerp(a, b, p);
const bc = lerp(b, c, p);
const cd = lerp(c, d, p);
const abc = lerp(ab, bc, p);
const bcd = lerp(bc, cd, p);
const abcd = lerp(abc, bcd, p);
@@ -90,4 +90,3 @@ export function drawCurve(ctx: CanvasRenderingContext2D, curve: Point[]) {
drawLine(ctx, curve[i], curve[i+1], 0xFFFFFF);
}
}