ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using object position to drive counter expressions.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Samuel Rustenburg
Using object position to drive counter expressions.
on Sep 10, 2018 at 8:57:40 pm
Last Edited By Samuel Rustenburg on Sep 10, 2018 at 8:59:59 pm

Hello

I'm having a difficult time wrapping my head around this request. I haven't been able to find anything remotely close to what im trying to execute and im beginning to think maybe its not possible.



Im hoping that I can have the blue curosr travel along a chart/graph and as it does, a legend will update with the data where the cursor lives.
• WHICH WEEK WERE ON
• THE TOTAL COST AT THIS POINT IN TIME
• AND THE DIFFERENCE IN SAVINGS.

I want to be able to just key frame the cursor and have the data automatically generate within the legend without having to manual key frame or "band-aid" fix with "time expressions".



Attached image is just the beginning stages of my animation but hopefully it gives an idea of what im trying to achieve.
(The 2 data entries at the bottom will not carry into the animation)


Any insight/work around on how to execute something like this, would be very helpful! Thanks!
- Samuel


Return to posts index

James Ronan
Re: Using object position to drive counter expressions.
on Sep 11, 2018 at 9:08:32 am

I think your looking for the linear function. Here's an example for the weeks

Apply this expression to the sourceText property of a text layer:


weekStart = 0;
weekEnd = 20;

posStart = 0;
posEnd = thisComp.width;

c = thisComp.layer("curser").transform.position[0];
week = linear(c,posStart,posEnd,weekStart,weekEnd);

Math.round(week);


This will update the week as the curser moves along the x-axis from one side of the comp to the other.

Hope that helps!


Return to posts index

Samuel Rustenburg
Re: Using object position to drive counter expressions.
on Sep 11, 2018 at 4:47:05 pm

Thanks for this James! This should be helpful.

This should work without any graph data correct. Will I need to include some sort of JSON or EXCEL data information to tell what the weekStart,weekEnd are to reference or is this experssion generating data based on the posStart and posEnd. (Sorry I'm a basic user of expressions).


Return to posts index


Samuel Rustenburg
Re: Using object position to drive counter expressions.
on Sep 11, 2018 at 4:58:53 pm

Sorry I should have plugged it in before responding.

I had an error come about on line 7 but I renamed my cursor layer to what was contained in the expression and the error has disappeared. I then had an issue of the week number staying a 3 but realized I have a the "curser" layer parented to a null to control the position of the cursor.

How would I modify the expression to target the X slider position of a null that the cursors X position is parented too (I separated the dimensions of the position) . I'm thinking the easiest would be to probably remove the null controller and just go straight from the layer like this expression is targeting.

I'm hoping that I can just modify your script here to also apply to the "DIFFERENCE/SAVINGS" value. Any suggestions on how to also achieve something like this script?

Thanks for the help! This is little code has saved me hours!!!!


Return to posts index

James Ronan
Re: Using object position to drive counter expressions.
on Sep 12, 2018 at 2:45:51 pm

How would I modify the expression to target the X slider position of a null that the cursors X position is parented too
Update the c variable to look at what ever you're using to move the curser. This could be either the null or a slider.

e.g. if you've linked it to a slider:
c = thisComp.layer("LAYER NAME").effect("Slider Control")("Slider").value;


It's possible if you update the linear expression with the y axis. But that will involve moving your curser that way too.

It gets more complicated if you want to only move your curser along the x axis and not the y.


Return to posts index

James Ronan
Re: Using object position to drive counter expressions.
on Sep 13, 2018 at 9:55:15 am

Okay I had a little crack at it this morning, maybe theres a better way, but here's where I'm at. This should allow you to animate the cursor along the x axis and it will display the current value on a text layer.

The rA variable is just an example array of stored values. 0,24,37,2,10,80,60,55,80,23
You can update that to read the data from a spreadsheet row or JSON file or w/e you choose.

On your cursor layer set two keyframes, the start position and end position and apply this expression to the source text property of your text layer. No easing though!


var rA = [0,24,37,2,10,80,60,55,80,23]; // result Array
var cursor = thisComp.layer("cursor"); // layer you choose to animate the x axis position
var xPos = cursor.position[0];
var startPos = cursor.position.key(1).value[0];
var endPos = cursor.position.key(2).value[0];
var aryN = linear(xPos,startPos,endPos,0,rA.length);
var aryNPrev = Math.floor(aryN);
var aryNNext = Math.ceil(aryN);
try{
txt = linear(aryN,aryNPrev,aryNNext,rA[aryNPrev],rA[aryNNext]);
txt.toFixed(2);
} catch (err){
rA[rA.length-1].toFixed(2)
}


Return to posts index


Samuel Rustenburg
Re: Using object position to drive counter expressions.
on Sep 13, 2018 at 3:22:23 pm

James you are amazing!!!

I had a little hiccup of trying to remove the decimal points when updating the week counter. I couldn't use the previous expression with this one easily (numbers weren't matching up to excel data). But I think I got that figured out by changing to rA[rA.length-1].toFixed(0). The one thing I cant figure out that isn't a big deal is that after the last keyframe the decimal points show back up (I just plan on splitting the layer and removing the expression).

I think I can manage the rest from this point on, but I am curious if this expression would allow for multiple keyframes of the "cursor". For example if we have a voice over that talks about the "breakeven point" we'd want the cursor to pause until its time to move onto the other cost specs. I can achieve this through splitting layers, but im sure there's a simpler/cleaner way of doing this.

Anyways, thanks for all your help here. Trying to understand this has allowed me to learn a couple new things and i'm going to try to understand this world more so I can write my own expressions at some point instead of bugging you guys! I'd love to buy you a cup of coffee or lunch for taking the time to help me out here. Shoot me a paypal or donation link if you got one, unless your local to Toronto, Canada area lets me up! ;p
- Sam


Return to posts index

James Ronan
Re: Using object position to drive counter expressions.
on Sep 14, 2018 at 7:59:37 am

This should remove the decimal after the last keyframe, and allow you to add multiple keyframes for pausing:



try{
var rA = [0,24,37,2,10,80,60,55,80,23]; // result Array
var cursor = thisComp.layer("cursor"); // layer you choose to animate the x axis position
var xPos = cursor.position[0];
var startPos = cursor.position.key(1).value[0];
var endPos = cursor.position.key(cursor.position.numKeys).value[0];
var aryN = linear(xPos,startPos,endPos,0,rA.length);
var aryNPrev = Math.floor(aryN);
var aryNNext = Math.ceil(aryN);
var txt = linear(aryN,aryNPrev,aryNNext,rA[aryNPrev],rA[aryNNext]);
txt.toFixed(0);
} catch (err){
rA[rA.length-1].toFixed(0)
}


Ah no worries dude. Happy to help!


Return to posts index

Samuel Rustenburg
Re: Using object position to drive counter expressions.
on Sep 18, 2018 at 12:35:13 pm

Fantastic!

I do have one final question. The expression is between two key frames, is there a chance that theres a line that can be added that allows any amount of key frames. I'd like the cursor to slow down for a part of the voice over/on screen text. Like at the break even point, the lines slow down or stop growing, then after the information is communicated I want to ramp the animation back up until we get to point 2 on the graph, again slowing down or stopping the line growth to give time to digest the data at this point in time.

I'll be able to achieve this through splitting layers Id assume, one last curve ball for you if your looking for another home run ;p


Return to posts index


James Ronan
Re: Using object position to drive counter expressions.
on Sep 18, 2018 at 1:15:48 pm

It should already allow you to add multiple keyframes, if thats what you mean.


Return to posts index

Kalleheikki Kannisto
Re: Using object position to drive counter expressions.
on Sep 11, 2018 at 2:47:23 pm

How are the graph values stored and how are the graphs generated?

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Samuel Rustenburg
Re: Using object position to drive counter expressions.
on Sep 11, 2018 at 4:11:39 pm

I currently have the graph data stored in a google excel, and I haven't decided on how the graphs are generated. I haven't used JSON files but it seems like it might be the way to go. I've done a conversion and got a JSON file from my EXCEL document (Im leaning on the side that it didn't translate properly).

I think I was just going to build out the graph with shape layers and just trick the animation. The thought that came to mind was to use sliders parented to positions of the shape layer/cursor, then the "Difference in savings" data I want generated is parented to those sliders.

I've done number counters over time, just never to the position of an object. Out of the gate I didn't think it was possible.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]