This commit is contained in:
Schluffe
2026-03-15 14:48:17 +01:00
parent 650b28a660
commit a1c4dd8401
4 changed files with 108 additions and 19 deletions
+46 -1
View File
@@ -1,8 +1,53 @@
import { createPolygon, type Polygon } from "#/engine/Polygon.ts";
import { defineScene } from "#/engine/Scene.ts";
import { createVector, type Vector } from "#/engine/Vector.ts";
import data from "./data.json";
const { process, linkScenes } = defineScene(data);
linkScenes(["testScene"] as const);
process((_ctx, _delta) => {});
const polygon = createPolygon(createVector(32, 32), [
createVector(0, 0),
createVector(0, 16),
createVector(16, 16),
]);
function drawPoint(
ctx: CanvasRenderingContext2D,
position: Vector,
radius: number = 2,
color: string = "#fff",
): void {
ctx.beginPath();
ctx.arc(position.x, position.y, radius, 0, 2 * Math.PI);
ctx.fillStyle = color;
ctx.fill();
}
function drawPoly(
ctx: CanvasRenderingContext2D,
poly: Polygon,
trigger: boolean = false,
): void {
drawPoint(ctx, poly.position);
ctx.beginPath();
ctx.moveTo(
poly.points[0].x + poly.position.x + 0.5,
poly.points[0].y + poly.position.y + 0.5,
);
for (let i = poly.points.length - 1; i >= 0; i--) {
ctx.lineTo(
poly.points[i].x + poly.position.x + 0.5,
poly.points[i].y + poly.position.y + 0.5,
);
}
ctx.strokeStyle = trigger ? "red" : "orange";
ctx.stroke();
}
process((ctx, _delta) => {
drawPoly(ctx, polygon);
});