File

src/toolbox/eraser/Eraser.ts

Index

Properties

Properties

height
height: number
Type : number
width
width: number
Type : number
x
x: number
Type : number
y
y: number
Type : number
import { ToolBox } from "../base/ToolBox";

export interface EraserOptions {
    x: number;
    y: number;
    width: number;
    height: number;
}

export class EraserTool extends ToolBox {
    public rectangular(options: EraserOptions) {
        this.history.push((ctx) => {
            ctx.clearRect(options.x, options.y, options.width, options.height);
        });
        return this;
    }

    public circular(options: Omit<EraserOptions, "width" | "height"> & { radius?: number }) {
        this.history.push((ctx) => {
            ctx.beginPath();
            ctx.arc(options.x, options.y, options.radius ?? 50, 0, 2 * Math.PI);
            ctx.clip();
            ctx.clearRect(0, 0, this.layer.width, this.layer.height);
            ctx.closePath();
        });
        return this;
    }
}

results matching ""

    No results matching ""