Draw cubic bezier curves in ActionScript?

What is the best way to draw cubic bezier curves programmatically in AS3? The Graphics class seems to support quadratic curves. :( I want to be able to do something like:

 var startPoint:Point = new Point(0, 0); var endPoint:Point = new Point(5, 5); var control1:Point = new Point(5, 0); var control2:Point = new Point(0, 5); var myBezier:Sprite = getBezier(startPoint, control1, control2, endPoint); 

For the performance target, I plan to have ~ 50 on stage at the same time.

+4
source share
3 answers

Note. Flash Player 11 includes its own method for drawing cubic curves, cube Tour () , which should be the fastest method if you are targeting FP11.

Last week, I wrote a class to draw arbitrary Bezier curves.

The code is not optimized, but works great in my tests. Performance is an acceptable event for animation (although I don’t think it’s a good idea to abuse it, because, as I said, it is not optimized, it makes no sense to use them for quadratic curves, of course, since the player can do it initially).

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

BezierCurve Class

Code example

I think that with the sample code you can figure out how to use it without problems (it is quite straightforward and somewhat commented on); but if you have problems ask!

Feel free to use it as you wish.

+4
source

If quadratic are embedded in this API call, you will need to understand Bezier well enough to write your own cubic implementation.

Like this .

+1
source

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

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

0
source

Source: https://habr.com/ru/post/1315732/


All Articles