Draw cubic bezier curves in Actionscript?

一世执手 提交于 2019-12-05 11:55:23
Juan Pablo Califano

Note: Flash Player 11 onwards includes a native method to draw cubic curves, cubicCurveTo() which should be the fastest method if you are targeting FP11.

Just last week I wrote a class to draw Bezier curves of arbitrary order.

The code is not optimized but works fine in my tests. Performance is acceptable event for doing animations (although I don't think it's a good idea to abuse it, since as I said it's not optimized; it doesn't make sense to use these for quadratic curves, of course, since the player can do that natively).

The code is here if you want to use it or take a look:

The BezierCurve class

Sample code

I think that with the sample code you will be able to figure out how to use it without trouble (it's quite straight forward and somewhat commented); but if you run into problems, ask away!

Feel free to use it as you see fit.

If quadratic are built into that API call, you'll have to understand Bezier well enough to write your own cubic implementation.

Like this.

This site lists and explains various ways of approximating cubic Bezier curves :
http://timotheegroleau.com/Flash/articles/cubic_bezier_in_flash.htm

At the very bottom he gives a method with the heading Fixed MidPoint approach which uses four quadratic curves as an approximation and seems to be the best in terms of accuracy and performance out of all the methods.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!