rings.ts hinzugefügt
This commit is contained in:
parent
e844fb4526
commit
182314faa0
28
rings.ts
Normal file
28
rings.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
arcForCircle(radius: number, gapSize: number) {
|
||||||
|
const svgSize = 100
|
||||||
|
const translate = svgSize / 2
|
||||||
|
|
||||||
|
const MAX_RADIANS = 2 * Math.PI
|
||||||
|
const gap = (gapSize === 0 ? 0.5 : gapSize) * MAX_RADIANS;
|
||||||
|
|
||||||
|
const startOffset = gap / 2
|
||||||
|
const availableTheta = MAX_RADIANS - gap
|
||||||
|
const largeArc = 1 // The full circle always goes around the large path
|
||||||
|
|
||||||
|
const thetaStart = MAX_RADIANS * 0.75 - startOffset;
|
||||||
|
const thetaEnd = thetaStart - availableTheta
|
||||||
|
|
||||||
|
if (gap < 0.1)
|
||||||
|
console.log(gap, startOffset, thetaStart, thetaEnd)
|
||||||
|
|
||||||
|
const [x1, y1] = [Math.cos(thetaStart) * radius + translate, -Math.sin(thetaStart) * radius + translate]
|
||||||
|
const [x2, y2] = [Math.cos(thetaEnd) * radius + translate, -Math.sin(thetaEnd) * radius + translate]
|
||||||
|
|
||||||
|
if (gapSize === 0)
|
||||||
|
return `M ${x1} ${y1}
|
||||||
|
A ${radius} ${radius} 0 1 0 ${x2} ${y2}
|
||||||
|
M ${x2} ${y2}
|
||||||
|
A ${radius} ${radius} 0 1 0 ${x1} ${y1}`
|
||||||
|
else
|
||||||
|
return `M ${x1} ${y1} A ${radius} ${radius} 0 ${largeArc} 1 ${x2} ${y2}`
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user