Am i right in thinking that from the Flash GUI you can only draw Cubic Bezier C开发者_如何学运维urves, and from Actionscript you can only draw Quadratic Bezier Curves ? Really?
This seems, well.. im sure it cant be.. It would be crazy if i had to write a Quadratic Bezier drawing app to work out some point co-ordinates.
If you're using the drawing API, then you can only draw Quadratic Bezier Curves using the curveTo() function. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#curveTo()
For proper bezier curves, it's not that hard, but you'll have to do it yourself. Some quick links with source code that I found: http://www.paultondeur.com/2008/03/09/drawing-a-cubic-bezier-curve-using-actionscript-3/
http://www.farmcode.org/post/2009/07/06/Fast-2D-Bezier-Library-for-ActionScript-3.aspx
Actually from Flash Player 11, released yesterday, the Drawing API supports Cubic Bezier curves:
(amongst other improvements and additions on this major release...)
http://www.adobe.com/devnet/flashplayer/articles/whats-new-flash-player11.html
This is a great post to draw Cubic Bezier curves in ActionScript using the fl.motion.BezierSegment class:
http://www.eleqtriq.com/2010/04/cubic-bezier-in-flash/
It's awesome - I created a complete curve with multiple segments with a fraction of the code and classes you need for most of the other links on this page:
var resolution :uint = 50;
var step :Number = 1/resolution;
function drawCurve(p0:Point, c0:Point, c1:Point, p1:Point)
{
var bezier :BezierSegment = new BezierSegment(p0, c0, c1, p1);
var t :Number = 0;
while (t <= 1)
{
var pt:Point = bezier.getValue(t);
with (graphics)
{
lineStyle(0.1, 0x00FFFF);
t == 0
? moveTo(pt.x, pt.y)
: lineTo(pt.x, pt.y);
}
t+=step;
}
pt = bezier.getValue(1);
graphics.lineTo(pt.x, pt.y);
}
It's a really great post!
精彩评论