lauchpioos/src/geometry.ts

38 lines
952 B
TypeScript
Raw Normal View History

2021-11-26 18:43:48 +00:00
import { Vector2D } from "./vector.js"
import * as shape from "./shapes.js"
2021-11-26 13:36:09 +00:00
class Geometry extends HTMLElement
2021-11-25 19:56:15 +00:00
{
2021-11-26 18:43:48 +00:00
private canvas: HTMLCanvasElement;
private context: CanvasRenderingContext2D;
2021-11-26 13:36:09 +00:00
constructor()
{
super();
this.attachShadow({mode: "open"});
2021-11-26 18:43:48 +00:00
let canvas = document.createElement("canvas");
canvas.width = 500;
canvas.height = 500;
let context = canvas.getContext("2d");
context.lineCap = "round";
context.lineJoin = "round";
context.strokeStyle = "black";
context.lineWidth = 1;
this.canvas = canvas;
this.context = context;
2021-11-26 13:36:09 +00:00
2021-11-26 18:43:48 +00:00
this.shadowRoot.append(this.canvas);
2021-11-26 13:36:09 +00:00
2021-11-26 18:43:48 +00:00
this.redraw();
}
private redraw()
{
shape.line(this.context, new Vector2D(), new Vector2D(300, 300));
shape.circle(this.context, new Vector2D(150, 150), 100);
2021-11-26 13:36:09 +00:00
}
2021-11-25 19:56:15 +00:00
}
2021-11-26 18:43:48 +00:00
customElements.define("geometry-sketch", Geometry);