added shapes

This commit is contained in:
Lauchmelder 2021-11-26 19:43:48 +01:00
parent ea4eb49670
commit 355b840471
6 changed files with 81 additions and 10 deletions

26
src/shapes.ts Normal file
View file

@ -0,0 +1,26 @@
import { Vector2D } from "./vector.js"
import { ShapeStyle } from "./shapeStyle.js";
export function line(ctx: CanvasRenderingContext2D, from: Vector2D , to: Vector2D, style: ShapeStyle = new ShapeStyle())
{
ctx.beginPath();
ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y);
ctx.lineWidth = style.strokeWidth;
ctx.strokeStyle = style.strokeColor;
ctx.stroke();
}
export function circle(ctx: CanvasRenderingContext2D, center: Vector2D, radius: number, style: ShapeStyle = new ShapeStyle())
{
ctx.beginPath();
ctx.arc(center.x, center.y, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = style.fillColor;
ctx.fill();
ctx.lineWidth = style.strokeWidth;
ctx.strokeStyle = style.strokeColor;
ctx.stroke();
}