Created
May 12, 2013 12:11
-
-
Save kt3k/5563353 to your computer and use it in GitHub Desktop.
cutting out rounded rectangle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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