-
For loops to create a dynamic array
Hiya
I have a middling knowlege of expressions. The only coding I do is with ae expressions, so please excuse any ignoramus comment i might make! And what I’m trying to do is quite ambitious for my level of code.
I’ve been working with a js developer here at work to get this expression working. We are trying to create an array that will store all the values between a given number of known points.
So imagine a spline with multiple points (e.g 4) drawn top to bottom in a comp. Those points have various X positions away from 0. We are then splitting the imaginary spline up into a given number of sub points (e.g 100). We are then trying take those known points and find all the X positions between those points on the spline for each of the sub points. So if there were 4 known points and 100 total sub points there would be 25 sub points between each known point.
This effectively generates a spline in an array from a given number of x positions. The Y positions of the points are at equal distance from each other for simplicity.
The following code we believe should work, however with no debug window in AE we are working blind. Is there anyone out there with the knowlege of expressions and js to know if there is a compatibility problem or something?
For example we are using a for loop within a for loop, is that possible in after effects? Is there anything else which might be a problem here? We thought there might be a problem with ‘push’ to add values to the array, but maybe not. It’s so hard to know where the code is falling down.
linearSpline = [];
TOTAL = thisComp.layer("TAPER CONTROLS").effect("Total Subdivisions")("Slider");
point0 = thisComp.layer("TAPER CONTROLS").effect("1")("Slider");
point1 = thisComp.layer("TAPER CONTROLS").effect("2")("Slider");
point2 = thisComp.layer("TAPER CONTROLS").effect("3")("Slider");
point3 = thisComp.layer("TAPER CONTROLS").effect("4")("Slider");
pointArray = [point0, point1, point2, point3];NUM = parseInt(thisProperty.propertyGroup(3).name.split(" ")[1],10);
//startW+((endW-startW)*(((100/TOTAL)*NUM)/100))
var SUB_POINT_COUNT = Math.ceil(TOTAL / pointArray.length);
var j;
for (var i = 0; i < pointArray.length; i = i + 1) {
// Find between values
if (i === (pointArray.length - 1)) {
break;
}var difference = Math.abs(pointArray[i] - pointArray[i+1]);
var subPointValue = Math.round(difference / SUB_POINT_COUNT);
j = difference;for (var v = 0; v < SUB_POINT_COUNT; v++) {
// linearSpline.push(subPointValue);
linearSpline[linearSpline.length] = subPointValue;
}}
linearSpline[NUM]
I hope that all makes sense, I’d be more than happy to help with more explanation of what we are trying to achieve if anyone can help!
thanks
H.