const canvas = document.getElementById("canvas1"); const ctx = canvas.getContext("2d"); const drawRect = function (options) { const { x, y, width, height, borderRadius, fillStyle, strokeStyle, lineWidth, } = options;
ctx.beginPath(); ctx.moveTo(x, y + borderRadius); ctx.lineTo(x, y + height - borderRadius); ctx.quadraticCurveTo(x, y + height, x + borderRadius, y + height); ctx.lineTo(x + width - borderRadius, y + height); ctx.quadraticCurveTo( x + width, y + height, x + width, y + height - borderRadius ); ctx.lineTo(x + width, y + borderRadius); ctx.quadraticCurveTo(x + width, y, x + width - borderRadius, y); ctx.lineTo(x + borderRadius, y); ctx.quadraticCurveTo(x, y, x, y + borderRadius); ctx.closePath();
if (fillStyle) { ctx.fillStyle = fillStyle; ctx.fill(); }
if (strokeStyle) { ctx.strokeStyle = strokeStyle; ctx.lineWidth = lineWidth || 2; ctx.stroke(); } };
const options = { x: 50, y: 50, width: 100, height: 50, borderRadius: 8, fillStyle: "#D0E8FF", strokeStyle: "#1890FF", };
drawRect(options);
|