Skip to content

@califa010 /gist:470097
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
package {
import com.mdiconcept.graphics.BezierCurve;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
/**
* ...
* @author Juan Pablo Califano <califa010@gmail.com>
*/
public class Main extends Sprite {
private var _sp:Sprite;
private var _bezierCurve:BezierCurve;
private var _position:Number = 0;
public function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
_sp = new Sprite();
addChild(_sp);
var points:Array = [
new Point(100,100),
new Point(90,30),
new Point(200,30),
new Point(230,100),
new Point(260,50),
];
_bezierCurve = new BezierCurve(points);
addEventListener(Event.ENTER_FRAME,handleEnterFrame);
}
private function handleEnterFrame(e:Event):void {
_position += 0.01;
if(_position > 1) {
_position = 0;
}
_sp.graphics.clear();
_bezierCurve.drawCurveEnvelope(_sp.graphics,_position);
_sp.graphics.lineStyle(2,0xff0000);
_bezierCurve.draw(_sp.graphics,100);
var bezierPoint:Point = _bezierCurve.getPointAtPosition(_position);
_sp.graphics.lineStyle(0);
_sp.graphics.drawCircle(bezierPoint.x,bezierPoint.y,3);
_sp.graphics.endFill();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.