Alex Printz
Forum Replies Created
-
Alex Printz
March 2, 2020 at 5:18 pm in reply to: Is it possible to combine two properties from textSource into new text layer?It looks like defining the style has to be first, and then the actual content is a subset of the style. I’m going to dig a bit more into this, haven’t looked much at the new style expressions much, and there’s hardly any documentation.
a = thisComp.layer("User Text").text.sourceText.charAt(2);
b = thisComp.layer("User Text").text.sourceText.getStyleAt(0);style = b;
style.setText(a);OR
thisComp.layer("User Text").text.sourceText.getStyleAt(0).setText(thisComp.layer("User Text").text.sourceText.charAt(2));
Alex Printz
Mograph Designer -
Use my expression above. The expression posted by the other user isn’t pulling anything from keyframes.
Alex Printz
Mograph Designer -
I’ve posted code below; just make sure your 2nd key’s value is different than the first key’s value (0px vs 10px).
linear(value, key(1).value, key(2).value, key(1).value, effect("Slider Value")(1))Alex Printz
Mograph Designer -
Sure, depending on if you’ve switched S to 0 or 1, it will orientate the turns; keeping either the next path’s X or Y the same as the previous point. Essentially, it doesn’t allow the snake to change both X and Y coordinates at a time, it only allows one to change, then change them both (which means only the one that didn’t initially change does).
so it looks like this:
J = [ Xcor[index – (if S equals 1, 1, else 0), Ycor[index-(if S does not equal 1, 1, else 0)];
Alex Printz
Mograph Designer -
Alex Printz
February 25, 2020 at 5:13 pm in reply to: using a layer’s visibility in an if/then expression on another layerDan I thought else If statements didn’t work in After Effects? Are they available again with the new Javascript engine?
Alex Printz
Mograph Designer -
This wouldn’t be super easy but not too difficult either; you should look at generating paths with random numbers inside an array, then build an if/or statement that will push coordinates from [X[n],Y[n]] or [X[n-1],Y[n]] whether the point is even or odd to get a right-angles pattern. You might have to figure out a way to step the incremental random numbers to a grid; say, round to the nearest integer and then multiply the offset by a standardized number.
Then add a trim path and a white stroke, that will be the snake layer; look at the stroke for the width, then measure the total length of your randomly generated path. calculate the distance and make a proportion and add that to the end to adjust the length. Keyframe the offset from 0 to 100;
Then make another path that grabs the first path and add a very short trim to that and a red stroke, that will be the food. You will need to build a randomized-step based on time that checks if the snake’s offset is equal to this offset for all previous frames, and if it is step forward.
Then to the snake’s trim end, you will need to check again if and when the offset was equal between the head and the food, and when it is add one incremental end equal to the width of the snake stroke.
I’ve stuck some code to the bottom for as far as I took this; this is for generating the path. After this, you’re on your own.
function splitArray(Arr){ //function to seperated X and Y coordinates;
a = []; b = [];
for (i=0;i<Arr.length;i++){
a[i] = Arr[i][0];
b[i] = Arr[i][1];
}
return [a,b];
}S = 1; //flips the direction of the split;
Astart = [-100,100]; //the start point
Aend = [2000,900]; //the end pointAseed = 12345; //a random seed
Anum = 8; //number of turns the snake will takeA=[Astart]; //creates array
seedRandom(Aseed,true);
for(i=0;i<Anum;i++){
//BUILD THE STEPPER CODE HERE
A.push(random(Astart, Aend));
}//splits the array into X and Y coordinates;
splitA = splitArray(A);
Xcor = splitA[0];
Ycor = splitA[1];P = [];
i = 1;
//offsets the coordinates to X/Y right angles based on even/odd calcs
while(i<A.length){
if(P.length % 2 == 0)
J = [Xcor[i-(S==1?1:0)],Ycor[i-(S!=1?1:0)]];
else{
J = [Xcor[i] ,Ycor[i]];
i++;
};
P.push(J);
}createPath(P,[],[],false)
Alex Printz
Mograph Designer -
you have to add the less-than symbols back in, they don’t translate well on web:
https://stackoverflow.com/questions/5068951/what-do-lt-and-gt-stand-for
Alex Printz
Mograph Designer -
That code is neat that it can invert the function based on the power being input, but honestly it seems pretty clunky to try and modify. Here is what you’re looking for, re-written into something more AE friendly that functions similar to the existing linear/ease functions.
Note that all that I do is check if the time is closer to the in or out point, and then invert the function. Really easy.
function easeInOutQuint(t, tMin, tMax, value1, value2){
b = value1;
c = value2-b;
d = tMax-tMin;
t = tMin < tMax ? thisLayer.linear(t,tMin,tMax,0,d) : thisLayer.linear(t,tMin,tMax,d,0);t /= d/2;
if (t < 1) return c/2*Math.pow(t,5) + b;
t -= 2;
return c/2*(Math.pow(t,5) + 2) + b;
}duration = 1;
start=[3000,-3000];
destination = [960,540];
exit = [-3000,3000];middle = (inPoint+outPoint)/2;
v = time < middle ? easeInOutQuint(time,inPoint,inPoint+duration,start,destination) : easeInOutQuint(time,outPoint-duration,outPoint,destination,exit);
Alex Printz
Mograph Designer -
Alex Printz
February 21, 2020 at 3:46 pm in reply to: Less expensive way to use Expression. e.g. sourceRectAtTime()…Expressions will always be harder on the system than keyframed data since the math has to be calculated live to get the option. Also note that if one layer’s expression is referencing another layer’s property’s output value , that other layer has to be calculated first, and it can create long chains.
So if layer A’s position is based on layer B’s opacity, and layer B’s opacity is based on a checkbox on layer C, and layer C is a precomp with master properties and has multiple iterations in the current comp, then when layer A’s position is
calculated it has to do the single master property of layer of C with the checkbox, then B’s opacity, then it can do A’s position.I *believe* once B’s opacity is calculated it isn’t recalculated again for the current frame, but I’m not 100% sure on that. Be aware that precomps with master properties have to be recalculated multiple times for each instance with a master property that is different than it’s source comp.
Another thing to mention is how AE render layers, which is always bottom to top in this order:
1. Comp Background color
2. Pre-Comp Layers
3. Non-Comp (footage, vector, solids, etc.) Layers
4. Lights
5. Cameras
6. Motion Blur
7. Audioso depending on how your comps are structured you can get some heavy back-and-forth expression calculations.
There’s been a potential workaround being developed a bit involving global variables. Note that these are kinda a hack at the moment, but depending on what you’re building it might be possible to push a lot of variables to global from a single element (null? text?) and then call those appropriately from other expressions so long as you’ve stacked your layers correctly (see my list above). This is a work in progress and being developed, and not be stable and may not be possible in later versions of AE.
A small trick I do for heavy expression comps is limit the expression calculations to specific points. I stuck some code down below that I use to only run expressions when time is on the layer’s duration in the timeline, which can help isolate when expressions are run without getting into specific time callouts. See below in the quoted section.
Adobe also has the new posterizeTime(0) available in CC 2020 that will only calculate once for the whole comp, also useful if you want to do the check only once.
I’m sure there’s a lot more, but that’s all I have off the top of my head.
if(time<inPoint||outPoint<time)value;else{
//all other code here}//end bracket after other code
Alex Printz
Mograph Designer -
You don’t need anything in particular to do that, just use the function I gave you. Here it is on the x-property.
function easeInOutQuad (t, tMin, tMax, value1, value2){
b = value1;
c = value2-b;
d = tMax-tMin;
t = tMin < tMax ? thisLayer.linear(t,tMin,tMax,0,d) : thisLayer.linear(t,tMin,tMax,d,0);
t /= d/2;
if (t < 1) return c/2*Math.pow(t,2) + b;
t--;
return -c/2 * (t*(t-2) - 1) + b;
}startVal = -2000;
endVal = 0;
startTime = thisLayer.inPoint;
endTime = startTime+1;px = easeInOutQuad (time, startTime, endTime, startVal, endVal);
[px,thisComp.height/2]
Alex Printz
Mograph Designer