/ Published in: ActionScript 3
This creates a scribble mouse trail effect. More importantly, it illustrates how you can easily use the greensock bezier plugin for TweenMax to actually draw bezier curves.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//get these classes at http://www.greensock.com/tweenmax/ import com.greensock.TweenMax; import com.greensock.plugins.BezierPlugin; import com.greensock.plugins.BezierThroughPlugin; var xA:Array=new Array(); var yA:Array=new Array(); xA.push(0); yA.push(0); addEventListener(Event.ENTER_FRAME,loop); var container = new Sprite(); addChild(container); function loop(e){ //trace(mouseX); xA.push(mouseX); yA.push(mouseY); if(xA.length>3){ var bezierObj:Object=BezierPlugin.parseBeziers({x:xA,y:yA},true); trace(bezierObj["x"].length); container.graphics.clear(); container.graphics.lineStyle(1); container.graphics.moveTo(xA[0],yA[0]); for( var i = 1; i<bezierObj["x"].length; i++){ container.graphics.curveTo(bezierObj.x[i][1],bezierObj.y[i][1],bezierObj.x[i][2],bezierObj.y[i][2]); } if(xA.length>20){ xA.shift(); yA.shift(); } } }
URL: http://www.adamcoulombe.info/lab/as3/scribble-trail.html