WIP WIP WIP

This commit is contained in:
Schluffe
2026-03-16 00:18:11 +01:00
parent a1c4dd8401
commit 6e95c538fb
6 changed files with 84 additions and 46 deletions
+37
View File
@@ -0,0 +1,37 @@
import type { Polygon } from "#/engine/Polygon.ts";
import type { Vector } from "#/engine/Vector.ts";
export function drawPoint(
ctx: CanvasRenderingContext2D,
position: Vector,
radius: number = 1,
color: string = "#fff",
): void {
ctx.beginPath();
ctx.arc(position.x, position.y, radius, 0, 2 * Math.PI);
ctx.fillStyle = color;
ctx.fill();
}
export function drawPolygon(
ctx: CanvasRenderingContext2D,
polygon: Polygon,
color: string = "#fff",
): void {
drawPoint(ctx, polygon.position);
ctx.beginPath();
ctx.moveTo(
polygon.points[0].x + polygon.position.x,
polygon.points[0].y + polygon.position.y,
);
for (let i = polygon.points.length - 1; i >= 0; i--) {
ctx.lineTo(
polygon.points[i].x + polygon.position.x,
polygon.points[i].y + polygon.position.y,
);
}
ctx.strokeStyle = color;
ctx.stroke();
}