Tutorial 105: Reverse Direction with Expressions

Joe Clay | Jan 12, 2018

This week, we're looking at reversing the direction of things like trim paths, and other effects that use ranges, like text animators. Our expression is simple and I'd even call it elegant since we basically end up with one quick math equation that suits both the forward and reversed directions.

You can apply this to pretty much any parameter you'd like if you need to reverse the way things are moving. I would highly recommend you animate from 0-1 and multiply that value by the maximum value of the range. So if you're modifying an angle for example, you want to end up with your value * 360. If you're using Flow or messing with easing, you might need to adjust them for such a small range. The multiplication should not have an effect since we're just changing the values after that.

So here's the basic expression. Don't forget to add a Checkbox Expression Control and call it Reverse. maximumValue is the extent of your range—i.e. 360 for an angle control.

rev = effect("Reverse")("Checkbox");
Math.abs(value-rev)*maximumValue;

We're using a checkbox on a Null for the next two examples. The conditional version I mentioned that changes the Trim Paths offset looks similar to the example below, but you'll have to modify it for your purposes. I knew the default value of 0 was fine since I originally animated it that way. But I left the Reverse condition as value so I could still slide the value around to set it up.

if(thisComp.layer("Control").effect("Reverse")("Checkbox").value) {
    value;
} else {
    0;
};

One of the strokes in our example had an animated offset, so I decided that rather than reanimating that range, I was going to just offset it by 120 degrees and subtract time * 30 as we go along, which offsets us by 120 degrees and moves the offset back enough to counteract and surpass how far it moves forward in the non-reversed version—thus moving it backwards in the reversed version.

if(thisComp.layer("Control").effect("Reverse")("Checkbox").value) {
    value-120-(time*30);
} else {
    value;
};

Depending upon how you set things up, you might be able to set up your offset with just the checkbox. For example if one way your offset is 20 degrees and the other is -20 degrees, you could set your value to 20 and do something like this:

rev = effect("Reverse")("Checkbox");
((rev*2)-1)*-value;

That way if Reverse is checked, it would be ((1 2) - 1) -20 = -20 which simplifies to 1 -20 = -20. Otherwise it would be (0 2) - 1) -20 = 20 which simplifies to -1 -20 = 20.

While that might seem convoluted at first, it was relatively easy to figure out. We need a range from -1 to 1 to multiply against our value. So that's a range 2 numbers wide. We only have a range one number wide—from 0-1. So now we just double the size of the range by multiplying by 2. This gets us a new range of 0-2 which is the right length but not the right numbers! So subtract one from the range and we offset our range from -1 to 1. Perfect.

So obviously there are a ton of ways to use this, especially if you really exploit the power of number ranges.

Become a Patron

If you'd like to help support Workbench, check out our Patreon page. For $5 a month, you get access to all of the tutorial project files we've made available as well as other monthly projects, rigs, R&D, elements, early product previews, and BTS content not available anywhere else!

Check out our Patreon Today