Skip to content

Instantly share code, notes, and snippets.

@christophemarois
Forked from anonymous/index.html
Last active August 29, 2016 23:44
Show Gist options
  • Save christophemarois/09c25b0584ccfe9728d59f37b829ca8e to your computer and use it in GitHub Desktop.
Save christophemarois/09c25b0584ccfe9728d59f37b829ca8e to your computer and use it in GitHub Desktop.
Curved SVG path generator. Demo: http://jsbin.com/cimoqob
function generateCurve (x1, y1, x2, y2, verticalBias) {
var line = []
var mx = x1 + (x2 - x1) / 2
line.push('M', x1, y1)
if (verticalBias) {
var my = y1 + (y2 - y1) / 2
line.push('C', x1, my, x2, my, x2, y2)
} else {
line.push('C', mx, y1, mx, y2, x2, y2)
}
return line.join(' ')
}
var path = document.querySelector('path')
path.setAttribute('d', generateCurve(0, 1, 200, 200))
<svg width="1000" height="1000">
<path d="" stroke="#000" stroke-width="2" fill="none" />
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment