public
Last active

  • Download Gist
gistfile1.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
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();
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.