Created
July 9, 2010 21:31
-
-
Save califa010/470097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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