Skip to content

Instantly share code, notes, and snippets.

@cjmdaixi
Created July 21, 2016 08:28
Show Gist options
  • Select an option

  • Save cjmdaixi/8f84430073136eee0c0b0f90a593b72f to your computer and use it in GitHub Desktop.

Select an option

Save cjmdaixi/8f84430073136eee0c0b0f90a593b72f to your computer and use it in GitHub Desktop.
Draw bezier curve smoothly between two points. Just like the curves in mind maps.
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
drawCurve(ctx, 100, 80, 0, 100);
function drawCurve(ctx, x1, y1, x2, y2){
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.bezierCurveTo((x1+x2)/2, y1, (x1+x2)/2, y2, x2, y2);
ctx.stroke();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment