This commit is contained in:
Maciej Caderek
2022-01-20 06:45:14 +01:00
parent 918a5dff4f
commit 8733c1c3ab
18 changed files with 308 additions and 226 deletions

View File

@@ -0,0 +1,27 @@
import { SquareStyle } from "../../types";
import createGradient from "../fill/createGradient";
import createPattern from "../fill/createPattern";
const drawRectangle = async (
ctx: CanvasRenderingContext2D,
width: number,
height: number,
x: number,
y: number,
squareStyle: SquareStyle
) => {
const fill = await (squareStyle.type === "solid"
? squareStyle.data.color
: squareStyle.type === "gradient"
? createGradient(ctx, squareStyle.data, width, height, x, y)
: createPattern(ctx, squareStyle.data));
if (fill === null) {
throw new Error("Cannot create canvas fill style");
}
ctx.fillStyle = fill;
ctx.fillRect(x, y, width, height);
};
export default drawRectangle;