“1 – cOrder=[1,2,3,0]” this does nothing. It works anticlockwise without this.
The rectangle does not complete because the last frame in the composition is invisible. You should subtract a frame from linear in order to fix this, not add to the percentage.
linear(time, 0, thisComp.duration-thisComp.frameDuration, 0, theEnd)
And you have to change those numbers for corners because you described it wrongfully in your post. You said in this order: bottom right, bottom left, top right, top left(it was bottom left, bottom right etc.). It actually was more complicated to me to do it the way you described it.
All in all, this should work now:
cW = thisComp.width;
cH = thisComp.height;
corners = [[-cW/2,-cH/2], [-cW/2,cH/2],[cW/2,cH/2],[cW/2,-cH/2]];
startCorner = thisComp.layer("Null 1").effect("Start_Point")("Slider").value%4;
p1 = (startCorner == 0) ? [] : corners.splice(0,startCorner);
corners = corners.concat(p1);
createPath(corners)
function arrIncludes(arr, element) {
for (var i = 0; i < arr.length; i++) {
if (element == arr[i]) return true
}
return false;
}
L = thisComp.width;
l = thisComp.height;
percentL = 50 * L / (L + l);
percentl = 50 * l / (L + l);
beginPoint = thisComp.layer("Null 1").effect("Start_Point")("Slider").value%4;
stopPoint = thisComp.layer("Null 1").effect("End_Point")("Slider") % 4;
shortPoints = [0, 2];
firstLInstances = Math.ceil(stopPoint / 2);
if (arrIncludes(shortPoints, beginPoint)) {
theEnd = percentl * firstLInstances + percentL * (stopPoint - firstLInstances);
} else {
theEnd = percentL * firstLInstances + percentl * (stopPoint - firstLInstances);
}
theEnd = theEnd == 0 ? 100 : theEnd;
linear(time, 0, thisComp.duration-thisComp.frameDuration, 0, theEnd)