Return to Snippet

Revision: 33505
at October 9, 2010 06:18 by adamcoulombe


Initial Code
//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();
		}
	}
	
}

Initial URL
http://www.adamcoulombe.info/lab/as3/scribble-trail.html

Initial Description
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.

Initial Title
Scribble Mouse Trail - Draw Bezier Curves using Greensock's Bezier Plugin

Initial Tags
flash

Initial Language
ActionScript 3