Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a path partially in HTML5's canvas?

Let's say I have curved path made using a serie of bezierCurveTo() calls. I'd like to make it appear progressively in an animation, by increasing the percentage of it that is drawn frame-after-frame. The problem is that I cannot find a standard way to draw only a part of a canvas path - would someon know of a good way (or even a tricky way) to achieve this?

like image 1000
Gnurou Avatar asked Mar 02 '13 03:03

Gnurou


2 Answers

Sure...and Simon Porritt did all the hard math for us!

jsBezier is a small lib with a function: pointAlongCurveFrom(curve, location, distance) that will let you incrementally plot each point along your Bezier curve.

jsBezier is available on GitHub: https://github.com/sporritt/jsBezier

like image 183
markE Avatar answered Sep 28 '22 09:09

markE


Just found a small library that does exactly that: https://github.com/camoconnell/lazy-line-painter

It relies on the Raphael lib (http://raphaeljs.com/), and the two put together do not make too big a payload.

like image 33
Gnurou Avatar answered Sep 28 '22 11:09

Gnurou