line path expressions


4 line expressions for After Effects TOC

line path with length, angle, anchorpoint, position

var lineLength = 200;
var anchorAtMiddleOrEnd = 100; //100 is middle and 0 is end of line
var myPosition = [0,0];
var angle = degreesToRadians( -90 );
//pointAndTangents grouped as: point, inTangent, outTangent
var pointsAndTangents = [
            [[myPosition[0] + Math.sin(angle) * lineLength * (anchorAtMiddleOrEnd * .005),
              myPosition[1] - Math.cos(angle) * lineLength * (anchorAtMiddleOrEnd * .005)],
             [0,0], [0,0]],
            [[myPosition[0] - Math.sin(angle) * lineLength * (1 - anchorAtMiddleOrEnd * .005),
              myPosition[1] + Math.cos(angle) * lineLength * (1 - anchorAtMiddleOrEnd * .005)],
             [0,0], [0,0]]
            ];

var myPoints = [];
var myinTangents = [];
var myoutTangents = [];
for(var i = 0;i<2;i++){
    myPoints.push(pointsAndTangents[i][0]);
    myinTangents.push(pointsAndTangents[i][1]);
    myoutTangents.push(pointsAndTangents[i][2]);
}
myIs_closed = false;
createPath(myPoints, myinTangents, myoutTangents, myIs_closed);

straight line path with controlpoints

// straight line between two expression control points
try{                var linePoint1 =    
                        effect("SLT point 1")("Point") 
                        - transform.position + transform.anchorPoint;
    }catch(error){  var linePoint1 = [-100,0];  };
try{                var linePoint2 = 
                        effect("SLT point 2")("Point") 
                        - transform.position + transform.anchorPoint;
    }catch(error){  var linePoint2 = [100,0];   };
//pointAndTangents grouped as: point, inTangent, outTangent
var pointsAndTangents = [
            [linePoint1,
             [0,0], [0,0]],
            [linePoint2,
             [0,0], [0,0]]
            ];
var myPoints = [];
var myinTangents = [];
var myoutTangents = [];
for(var i = 0;i<2;i++){
    myPoints.push(pointsAndTangents[i][0]);
    myinTangents.push(pointsAndTangents[i][1]);
    myoutTangents.push(pointsAndTangents[i][2]);
}
myIs_closed = false;
createPath(myPoints, myinTangents, myoutTangents, myIs_closed);

curved line path with controlpoints

// curved line between two expression control points
try{                var linePoint1 =    
                        effect("SLT point 1")("Point") 
                        - transform.position + transform.anchorPoint;
    }catch(error){  var linePoint1 = [-100,0];  };
try{                var linePoint2 = 
                        effect("SLT point 2")("Point") 
                        - transform.position + transform.anchorPoint;
    }catch(error){  var linePoint2 = [100,0];   };

var delta = linePoint2[0] - linePoint1[0];
var factor = .5;

//pointAndTangents grouped as: point, inTangent, outTangent
var pointsAndTangents = [
            [linePoint1,
             [0,0], [delta*factor,0]],
            [linePoint2,
             [-delta*factor,0], [0,0]]
            ];
var myPoints = [];
var myinTangents = [];
var myoutTangents = [];
for(var i = 0;i<2;i++){
    myPoints.push(pointsAndTangents[i][0]);
    myinTangents.push(pointsAndTangents[i][1]);
    myoutTangents.push(pointsAndTangents[i][2]);
}
myIs_closed = false;
createPath(myPoints, myinTangents, myoutTangents, myIs_closed);

arrow with controlpoints

// arrow between two expression control points
try{                var linePoint1 =    
                        effect("SLT point 1")("Point") 
                        - transform.position + transform.anchorPoint;
    }catch(error){  var linePoint1 = [-100,0];  };
try{                var linePoint2 = 
                        effect("SLT point 2")("Point") 
                        - transform.position + transform.anchorPoint;
    }catch(error){  var linePoint2 = [100,0];   };

var delta = linePoint2[0] - linePoint1[0];
var factor = .5;
var vector = linePoint2 - linePoint1;
var anglePoint = Math.atan2(vector[1], vector[0]) + degreesToRadians(90);
var trianglepoints = [[0,0],[17.3,-30],[-17.3,-30]];

function rotatePoint(i, angle){
    rotatedpointx = trianglepoints[i][0] * Math.cos(angle) 
                    - trianglepoints[i][1] * Math.sin(angle);
    rotatedpointy = trianglepoints[i][0] * Math.sin(angle) 
                    + trianglepoints[i][1] * Math.cos(angle);
    return [rotatedpointx,rotatedpointy]
}

//pointAndTangents grouped as: point, inTangent, outTangent
var pointsAndTangents = [
            [rotatePoint(0, anglePoint) + linePoint1,
             [0,0], [0,0]],
            [rotatePoint(1, anglePoint) + linePoint1,
             [0,0], [0,0]],
            [rotatePoint(2, anglePoint) + linePoint1,
             [0,0], [0,0]],
            [linePoint1,
             [0,0], [0,0]],
            [linePoint2,
             [0,0], [0,0]]
            ];
var myPoints = [];
var myinTangents = [];
var myoutTangents = [];
for(var i = 0;i<5;i++){
    myPoints.push(pointsAndTangents[i][0]);
    myinTangents.push(pointsAndTangents[i][1]);
    myoutTangents.push(pointsAndTangents[i][2]);
}
myIs_closed = false;
createPath(myPoints, myinTangents, myoutTangents, myIs_closed);