RSS
email

Drawing Smooth curve from Flash



I got the sample from here and
http://www.strille.net/works/misc/followScriptedPath/followPath.html

and Modified to as type....

thanks fot the author.....

Smooth_path.as




class Smooth_path {
public var pathDetail:Number = .05;
public var drawPath:Boolean = true;
public function Smooth_path(myPath:MovieClip, line_data_arr:Array) {
trace("sdghafasjdgf"+[myPath, line_data_arr]);
// how smooth the path is, should not be much lower than 0.05, and must be > 0
//var myPath:MovieClip = _root.createEmptyMovieClip("myPath", _root.getNextHighestDepth());
Path(myPath);
// create a new path
for (var i:Number = 0; i<=line_data_arr.length-1; i++) { trace([line_data_arr[i].x, line_data_arr[i].y]); addPoint(myPath, line_data_arr[i].x, line_data_arr[i].y); } calcPath(myPath, pathDetail, drawPath); } private function Path(myPath:MovieClip) { myPath.x = []; myPath.y = []; myPath.numOfPoints = 0; myPath.subPointDis = null; myPath.subPointX = null; myPath.subPointY = null; myPath.subPointXl = null; myPath.subPointYl = null; myPath.totalDistance = 0; } private function addPoint(myPath:MovieClip, x, y) { myPath.x.push(x); myPath.y.push(y); myPath.numOfPoints++; } private function createContainers(myPath:MovieClip) { if (myPath.pathContainer == undefined) { if (_root["pathMC"] == undefined) { _root.createEmptyMovieClip("pathMC", _root.getNextHighestDepth()); } _root["pathMC"].createEmptyMovieClip("lineMC", _root.pathMC.getNextHighestDepth()); _root["pathMC"].createEmptyMovieClip("anchorMC", _root.pathMC.getNextHighestDepth()); myPath.pathContainer = _root["pathMC"].lineMC; myPath.anchorContainer = _root["pathMC"].anchorMC; } } private function calcPath(myPath:MovieClip, pathStepSize, drPath) { if (drPath) { trace(typeof (myPath)); createContainers(myPath); myPath.pathContainer.clear(); myPath.pathContainer.lineStyle(0, 0xcccccc, 100); //myPath.pathContainer.moveTo(myPath.x[0], myPath.y[0]); myPath.pathContainer._x = myPath.x[0]; myPath.pathContainer._y = myPath.y[0]; } else if (myPath.pathContainer) { myPath.pathContainer.removeMovieClip(); myPath.anchorContainer.removeMovieClip(); delete myPath.pathContainer; } myPath.subPointDis = [0]; myPath.subPointX = [myPath.x[0]]; myPath.subPointY = [myPath.y[0]]; myPath.subPointDisl = []; myPath.subPointXl = []; myPath.subPointYl = []; for (var t = -1.0; t<=myPath.numOfPoints-3; i++) { for (var t = pathStepSize; t<1.0+pathstepsize/2; b1 =" -t*(t-1)*(t-2)/6;" b2 =" (t+1)*(t-1)*(t-2)/2;" b3 =" -(t+1)*t*(t-2)/2;" b4 =" (t+1)*t*(t-1)/6;" x =" myPath.x[i-1]*b1+myPath.x[i]*b2+myPath.x[i+1]*b3+myPath.x[i+2]*b4;" y =" myPath.y[i-1]*b1+myPath.y[i]*b2+myPath.y[i+1]*b3+myPath.y[i+2]*b4;" dx =" x-myPath.subPointX[myPath.subPointDis.length-1];" dy =" y-myPath.subPointY[myPath.subPointDis.length-1];" d =" Math.sqrt(dx*dx+dy*dy);" t =" 1.0+pathStepSize;" b1 =" -t*(t-1)*(t-2)/6;" b2 =" (t+1)*(t-1)*(t-2)/2;" b3 =" -(t+1)*t*(t-2)/2;" b4 =" (t+1)*t*(t-1)/6;" x =" myPath.x[myPath.numOfPoints-4]*b1+myPath.x[myPath.numOfPoints-3]*b2+myPath.x[myPath.numOfPoints-2]*b3+myPath.x[myPath.numOfPoints-1]*b4;" y =" myPath.y[myPath.numOfPoints-4]*b1+myPath.y[myPath.numOfPoints-3]*b2+myPath.y[myPath.numOfPoints-2]*b3+myPath.y[myPath.numOfPoints-1]*b4;" dx =" x-myPath.subPointX[myPath.subPointDis.length-1];" dy =" y-myPath.subPointY[myPath.subPointDis.length-1];" d =" Math.sqrt(dx*dx+dy*dy);" totaldistance =" myPath.subPointDis[myPath.subPointDis.length-1];" style="color: rgb(255, 0, 0);">testsmooth.fla


type the following in first frame...


var line_data_arr:Array = new Array();
line_data_arr.push({x:54.1666666666667, y:500});
line_data_arr.push({x:108.333333333333, y:0});
line_data_arr.push({x:162.5, y:307.055555555556});
line_data_arr.push({x:216.666666666667, y:483.333333333333});
line_data_arr.push({x:270.833333333333, y:487});
line_data_arr.push({x:325, y:431.444444444444});
line_data_arr.push({x:379.166666666667, y:472.222222222222});
var myPath:MovieClip = _root.createEmptyMovieClip("myPath", _root.getNextHighestDepth());
var pp:Smooth_path = new Smooth_path(myPath, line_data_arr);



---------------------------

test flash ..........


Source Files






Bookmark and Share

0 comments:

 

Recent Posts

Recent Visitors

Donate Me

About Me

My photo
Chennai, Tamil nadu, India
Nothing more to say about me.. Just a Action Script programmer / Flex developer having 4.5 years of experience.