dom-helpers.ts

43 lines | 1.577 kB Blame History Raw Download
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.drawRect(x, y, width, height, color);
}

export function box(x: number, y: number, width: number, height: number, color?: string): void {
    var renderCanvas = <RenderCanvas>document.getElementsByTagName("render-canvas")[0];
    renderCanvas.queueRect(x, y, width, height, color);
}

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.executeDrawQueue();
}

export function getRandomColor(randomOpacity: boolean = true): string {
    return "rgba(" + getRandom(0,255) + ", " + getRandom(0,255) + ", " + getRandom(0,255) + ", " + (randomOpacity ? Math.random() + 0.1 : "1") + ")";
}