Skip to main content
Jøsh994
Known Participant
March 24, 2024
Answered

Using CSV times to perform eases

  • March 24, 2024
  • 1 reply
  • 1383 views

Hi! I've been trying to work out how to create a racing leaderboard in after effects that's driven by a CSV (an image of this is shown below).

 

The sheet below has the following columns:

P1: a random racer's position in the order
P2: another random racer (we'll ignore them for the time being)
SecInt: conversion of minutes, seconds, and milliseconds to decimal seconds

 

The racer positions are meant to be displayed using a text box, and I want it to ease every time there's an overtake (as indicated by the times on the timer). I wrote a bunch of code that was borrowed from one of my previous projects, but I can't seem to make it work.

 

Here's the code I have right now inside the source text of P1's position:

OT = footage("Placements.csv");
genData = footage("General Data.csv");
var numbering = ?; // This must be manually set!
var rowNum = 1;
var rowCount = genData.dataValue([1, 8]);
var output;

function easeTo (A, B, C, D) {
var output = ease(time, A, B, C, D);
return Math.round(output);
}

while (rowNum < rowCount)
{
//Step 1: Setting the Variables
startTime = OT.dataValue([4, rowNum]);
endTime = OT.dataValue([4, rowNum]) + 1/5;
prevPos = OT.dataValue([4 + numbering, rowNum - 1]);
newPos = OT.dataValue([4 + numbering, rowNum]);
//Step 2: Creating the Ease
while (time < endTime)
{
output = easeTo (startTime, endTime, prevPos, newPos);
}
//Step 3: Increment + Return to Start
rowNum++;
}
[output]


Note: I have a separate area (in `generalData`) that allows me to enter the number of rows in the CSV. I don't need to have it run infinitely.

This topic has been closed for replies.
Correct answer Dan Ebberts

Hello Dan, thank you for your reply.

1. The racers are all moving (I have them in separate compositions); I just need to establish how to move one of them, and then I'll have a foothold as to how it should work.
2. I'm only working on easing the placements right now, as the vertical position on screen will follow afterward.
3. Each ease takes 0.2 seconds, hence the + 1/5 at the end of:
> endTime = OT.dataValue([4, rowNum]) + 1/5;
4. P3 and P5 being at the same position is a mistake. Sorry about that!
5. I have posted what the row should look like before and after.


It's a little tricky, but this might be helpful. First, I think you should drag the csv into your timeline so the expression can easily reference the number of rows from the data itself. Then try this as a source text expression:

 

OT = footage("Placements.csv");
easeTime = .2;
myCol = 5;
numRows = thisComp.layer("Placements.csv")("Data")("Number of Rows");

pos = OT.dataValue([myCol,0]);
for (i = 0; i < numRows; i++){
  if(time < OT.dataValue([4,i])) break;
}
i--;
if (i > 0){
  t1 = OT.dataValue([4,i]);
  t2 = t1 + easeTime;
  v1 = OT.dataValue([myCol,i-1]);
  v2 = OT.dataValue([myCol,i]);
  pos = ease(time,t1,t2,v1,v2);
}
pos

You may want to round pos, as you did in your expression, but without the rounding you'll see the easing.

 

1 reply

Dan Ebberts
Community Expert
Community Expert
March 24, 2024

It's not clear from your code (to me at least) exactly how your animation is supposed to work. A detailed description would very helpful.

Jøsh994
Jøsh994Author
Known Participant
March 24, 2024

Hi Dan,

My apologies for the confusion. Let me try to do a better explanation.

 

Shown below is a single row on the timing tower. Notice the square with the number 1 inside it. This is the racer's current position (henceforth referred to as curPos) in the race.

 

Now, if you take a look at the Placements.csv that I linked, the racer moves up to 1st place at 0:07:32 (secInt is just there to convert the timer to a single value that can be used for expressions). What I want to do is the following:

- Every time the timer reaches a point where a new overtake is made, do the following:
- Ease curPos from its previous value to its new value. For instance, at 0:07.32, it should ease from 3 to 1.
- Do this for every single row in the CSV.

 

Please let me know if this is still unclear.

Thanks,
Josh994

Jøsh994
Jøsh994Author
Known Participant
March 24, 2024

I forgot to attach this...