1
0
Fork 0
mirror of https://github.com/1disk/edp445.git synced 2024-08-14 22:47:02 +00:00
edp445/node_modules/canvacord/plugins/rect.js

22 lines
897 B
JavaScript
Raw Normal View History

2022-12-03 05:44:44 +00:00
module.exports = (ctx, x, y, height, width, color, stroke = false, lineWidth = 1) => {
if (!ctx) throw new Error("Missing canvas context!");
if (isNaN(x)) throw new Error(`Expected height to be a number, received ${typeof height}!`);
if (isNaN(y)) throw new Error(`Expected width to be a number, received ${typeof width}!`);
if (isNaN(height)) throw new Error(`Expected height to be a number, received ${typeof height}!`);
if (isNaN(width)) throw new Error(`Expected width to be a number, received ${typeof width}!`);
if (!color) color = "#000000";
stroke = !!stroke;
ctx.beginPath();
if (stroke) {
ctx.lineWidth = lineWidth;
ctx.strokeStyle = color;
ctx.rect(x, y, width, height);
ctx.stroke();
} else {
ctx.fillStyle = color;
ctx.fillRect(x, y, width, height);
}
ctx.closePath();
return ctx;
};