Created
June 26, 2024 07:59
-
-
Save pie6k/92eeffe009366ad443219595342baea3 to your computer and use it in GitHub Desktop.
Get SVG Squircle Path
This file contains hidden or 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
const iOSPreset = { | |
r1: 0.0586, | |
r2: 0.332, | |
}; | |
function getSmoothSquirclePath(w: number, h: number, r1: number, r2: number) { | |
r1 = Math.min(r1, r2); | |
return ` | |
M 0,${r2} | |
C 0,${r1} ${r1},0 ${r2},0 | |
L ${w - r2},0 | |
C ${w - r1},0 ${w},${r1} ${w},${r2} | |
L ${w},${h - r2} | |
C ${w},${h - r1} ${w - r1},${h} ${w - r2},${h} | |
L ${r2},${h} | |
C ${r1},${h} 0,${h - r1} 0,${h - r2} | |
L 0,${r2} | |
` | |
.trim() | |
.replace(/\n| {2,}/g, " "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment