dom-helpers.ts
Home
/
outputframe-app /
injects /
dom-helpers.ts
import { RenderCanvas } from "../elements/render-canvas/render-canvas";
export function clear() {
}
export function rect(x: number, y: number, width: number, height: number, color?: string): void {
var renderCanvas = <RenderCanvas>document.getElementsByTagName("render-canvas")[0];
renderCanvas.rect(x, y, width, height, color, false);
}
export function box(x: number, y: number, width: number, height: number, color?: string): void {
var renderCanvas = <RenderCanvas>document.getElementsByTagName("render-canvas")[0];
renderCanvas.rect(x, y, width, height, color, true);
}
export function getWidth(): number {
var renderCanvas = <RenderCanvas>document.getElementsByTagName("render-canvas")[0];
return renderCanvas.units.width;
}
export function getHeight(): number {
var renderCanvas = <RenderCanvas>document.getElementsByTagName("render-canvas")[0];
return renderCanvas.units.height;
}
export function getCenter(): number {
var renderCanvas = <RenderCanvas>document.getElementsByTagName("render-canvas")[0];
return renderCanvas.units.height / 2;
}
export function getRandom(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
export function executeDrawQueue(): void {
var renderCanvas = <RenderCanvas>document.getElementsByTagName("render-canvas")[0];
renderCanvas.draw();
}
export function getRandomColor(): string {
var prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
var from = prefersDarkScheme.matches ? 127 : 0;
var to = prefersDarkScheme.matches ? 255 : 127;
return "rgba(" + getRandom(from,to) + ", " + getRandom(from,to) + ", " + getRandom(from,to) + ", " + ("1") + ")";
}