Skip to content

Instantly share code, notes, and snippets.

@kt3k
Created May 12, 2013 12:11
Show Gist options
  • Save kt3k/5563353 to your computer and use it in GitHub Desktop.
Save kt3k/5563353 to your computer and use it in GitHub Desktop.
cutting out rounded rectangle.
var cutRoundedRect = function(ctx, radius, x, y, w, h) {
var left = x;
var top = y;
var right = x + w;
var bottom = y + h;
ctx.globalCompositeOperation = 'destination-in';
ctx.fillStyle = 'black';
ctx.beginPath();
ctx.moveTo(left + radius, top);
ctx.lineTo(right - radius, top);
ctx.quadraticCurveTo(right, top, right, top + radius);
ctx.lineTo(right, bottom - radius);
ctx.quadraticCurveTo(right, bottom, right - radius, bottom);
ctx.lineTo(left + radius, bottom);
ctx.quadraticCurveTo(left, bottom, left, bottom - radius);
ctx.lineTo(left, top + radius);
ctx.quadraticCurveTo(left, top, left + radius, top);
ctx.fill();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment