-
-
Save christophemarois/09c25b0584ccfe9728d59f37b829ca8e to your computer and use it in GitHub Desktop.
Curved SVG path generator. Demo: http://jsbin.com/cimoqob
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
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)) |
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
<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