On a shape layer I have a group that contains a stroked path with a trim path operator. I'd like to fill the whole path with stroke segments of different color and length by duplicating the group. The color part is working but I am getting confused how to calculate the starting and end points for each segment. Offset will be used to drive the animation.
For the Start value this works fine (it sums the values of End):
var segmentId = thisProperty.propertyGroup(3).propertyIndex;
var numberOfSegments = thisLayer("Contents").numProperties;
var startPercentage = 0;
for(var i = numberOfSegments; i > segmentId; i--) {
startPercentage += thisLayer("Contents")(segmentId).content("Trim Paths 1").end;
}
startPercentage;
But how do I calculate the end value for each. This is my attempt but it is not working. The logic is to find out the end value of the previous segment and add the new length to it. At the moment it just shoots both Start and End to 100%. There is some kind of unwated reference loop?
var segmentId = thisProperty.propertyGroup(3).propertyIndex;
var numberOfSegments = thisLayer("Contents").numProperties;
var previousSegmentEnd = numberOfSegments < 2 ? 0 : thisLayer("Contents")(segmentId + 1).content("Trim Paths 1").end;
var segmentLengths = [6, 8, 10, 13, 16, 21];
seedRandom(segmentId, timeless=true);
var currentLength = segmentLengths[Math.floor(random(segmentLengths.length))];
previousSegmentEnd + currentLength;
Probably simple but I just seem to be stuck with this. Any help is much appreciated.