# 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 + Math.sin(angle) * lineLength * (anchorAtMiddleOrEnd * .005),
myPosition - Math.cos(angle) * lineLength * (anchorAtMiddleOrEnd * .005)],
[0,0], [0,0]],
[[myPosition - Math.sin(angle) * lineLength * (1 - anchorAtMiddleOrEnd * .005),
myPosition + 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]);
myinTangents.push(pointsAndTangents[i]);
myoutTangents.push(pointsAndTangents[i]);
}
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]);
myinTangents.push(pointsAndTangents[i]);
myoutTangents.push(pointsAndTangents[i]);
}
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 - linePoint1;
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]);
myinTangents.push(pointsAndTangents[i]);
myoutTangents.push(pointsAndTangents[i]);
}
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 - linePoint1;
var factor = .5;
var vector = linePoint2 - linePoint1;
var anglePoint = Math.atan2(vector, vector) + degreesToRadians(90);
var trianglepoints = [[0,0],[17.3,-30],[-17.3,-30]];

function rotatePoint(i, angle){
rotatedpointx = trianglepoints[i] * Math.cos(angle)
- trianglepoints[i] * Math.sin(angle);
rotatedpointy = trianglepoints[i] * Math.sin(angle)
+ trianglepoints[i] * 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]);
myinTangents.push(pointsAndTangents[i]);
myoutTangents.push(pointsAndTangents[i]);
}
myIs_closed = false;
createPath(myPoints, myinTangents, myoutTangents, myIs_closed);