Created
August 15, 2023 05:36
-
-
Save hellozimi/56d10ed48e3c937314cf48dbacc3d286 to your computer and use it in GitHub Desktop.
Generate reverse circle clip-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
// number of verticies | |
const precision = 64 | |
// radius in percent (where 50 = full circle) | |
const containerWidth = 40 | |
const borderWidth = 1 | |
const radius = borderWidth/containerWidth // 48.5 | |
const points = [...Array(precision)].map((_, i) => { | |
let a = -i/(precision-1)*Math.PI*2; | |
let x = Math.cos(a)*radius + 50; | |
let y = Math.sin(a)*radius + 50; | |
return `${x.toFixed(3)}% ${y.toFixed(3)}%` | |
}) | |
const outline = ['100% 50%', '100% 100%', '0 100%', '0 0', '100% 0', '100% 50%'] | |
const polygon = outline.concat(points).join(', '); | |
console.log(`clip-path: polygon(${polygon});`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment