Skip to content

Instantly share code, notes, and snippets.

@arnoson
Created November 4, 2021 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnoson/34c24424ab3e4bae65690a8e814d9102 to your computer and use it in GitHub Desktop.
Save arnoson/34c24424ab3e4bae65690a8e814d9102 to your computer and use it in GitHub Desktop.
Create a dash array with holes in it
const path = new Path.Circle({
radius: 200,
strokeColor: 'blue',
center: view.center,
strokeCap: 'round',
strokeWidth: 3
})
const gap = 50
const offsets = []
const updateDashes = () => {
const dashes = []
let lastOffset = 0
for (const offset of offsets) {
dashes.push(offset - lastOffset - gap / 2)
dashes.push(gap)
lastOffset = offset + gap / 2
}
dashes.push(path.length)
path.dashArray = dashes
}
function onMouseDown(event) {
const point = path.getNearestPoint(event.point)
const offset = path.getOffsetOf(point)
offsets.push(offset)
updateDashes()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment