HTML5 Canvas Modify Curves with Anchor Points Using KineticJS

Posted on January 7th, 2012 by Eric Rowell

Instructions: Use your mouse or finger and drag and drop the anchor points to modify the curvature of the quadratic curve and the Bezier curve. Open in new window

Code Editor

17 Comments

  1. Oleg says:

    Looks really cool, great job!

  2. Oleg says:

    @Eric, how can I move shape to background layer?

  3. Inn says:

    Add excanvas for ie9-

  4. Eric Rowell says:

    @Oleg I posted your question with the answer on the KineticJS Forum here:

    http://kineticjs.com/forum/viewtopic.php?f=5&t=8

  5. Eric Rowell says:

    @Inn IE9 fully supports the 2d context so excanvas shouldn’t be needed.

  6. Monski says:

    Can i apply it also on text? to curve?

  7. yoh says:

    Hi, follow up on monski’s post. is there a way to curve a text?? we really need that functionality. thanks

  8. Eric Rowell says:

    it’s absolutely possible, but certainly not trivial. I’ve avoided creating a tutorial that shows placing text along an arbitrary curve because the return on investment would be fairly low (very complex work, and not a lot of people need this).

    Have you checked out my tutorial on drawing text along an arc? The approach would be very similar except that you’d have to calculate the tangent angle at each point (for a circle, the tangent is always 90 degrees from the center

    http://www.html5canvastutorials.com/labs/html5-canvas-text-along-arc-path/

  9. yoh says:

    thanks :D

  10. Kevin says:

    This looks like the wrong source code… Is it the “modify shape color on click code?” I’d love to see the code for this. Very nice library btw. =) Thanks in advance!

  11. Eric Rowell says:

    @Kevin whoops sorry about this! Made a mistake when updating this lab. Fixed now :)

  12. Marc says:

    Hi,

    Can a layer have points like a polygon? So I could add an event on the layer like mouseout but for a specific area only. Because Stage contains the whole area and I need to bind it on a specific area.

  13. HPH says:

    Hallo Eric, is their a possibility to have a type of curve with 3 anchor points?

  14. Eric Rowell says:

    @Marc I’m not quite sure that makes sense – layers contain shapes, and shapes are the visual components of your canvas app. You can however, add event listeners to layers, but these listeners are applied to all of it’s children.

    If you want mouse functionality for a specific area, you might try creating an invisible polygon (just don’t set the fill property)

    Cheers!

  15. Eric Rowell says:

    @HPH sure, you would just need to combine three quadratic curves together

  16. HPH says:

    How connect them constrain?

Leave a Comment