Last active
June 4, 2024 07:01
-
-
Save danielpquinn/dd966af424030d47e476 to your computer and use it in GitHub Desktop.
Draw SVG Rounded Rectangle Path
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
/** | |
* Get path data for a rounded rectangle. Allows for different radius on each corner. | |
* @param {Number} w Width of rounded rectangle | |
* @param {Number} h Height of rounded rectangle | |
* @param {Number} tlr Top left corner radius | |
* @param {Number} trr Top right corner radius | |
* @param {Number} brr Bottom right corner radius | |
* @param {Number} blr Bottom left corner radius | |
* @return {String} Rounded rectangle SVG path data | |
*/ | |
var roundedRectData = function (w, h, tlr, trr, brr, blr) { | |
return 'M 0 ' + tlr | |
+ ' A ' + tlr + ' ' + tlr + ' 0 0 1 ' + tlr + ' 0' | |
+ ' L ' + (w - trr) + ' 0' | |
+ ' A ' + trr + ' ' + trr + ' 0 0 1 ' + w + ' ' + trr | |
+ ' L ' + w + ' ' + (h - brr) | |
+ ' A ' + brr + ' ' + brr + ' 0 0 1 ' + (w - brr) + ' ' + h | |
+ ' L ' + blr + ' ' + h | |
+ ' A ' + blr + ' ' + blr + ' 0 0 1 0 ' + (h - blr) | |
+ ' Z'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is beautiful, thanks! I asked ChatGPT to make it even more beautifuler 😉