So let me explain, I have a json file with numbers and the duration of how long each number should be displayed which is 4 seconds. I want the slider to show the first number (which is 1,000) and then four seconds later display 2,000 (which is second number) . But have it showing all the numbers in between 1,000-2,000.
My array looks like this:
[
{
"ID": 1,
"slider": 1000,
"duration": .4
},
{
"ID": 2,
"slider": 2000,
"duration": .4
},
{
"ID": 3,
"slider": 3828.52,
"duration": .4
}
]
And I have found a code that works, it starts at 0 seconds and animates 1,000 counting up to 2,000. The only problem with this code is that it has a delay, So when the animation starts it stays at 1,000 for about one whole second and then starts to animate counting up to 2,000 at the four second mark. Then same thing at the four second mark, it stays at 2,000 for a second and then animates. How do i prevent this delay? I would like it to be constant. Here is the code which works but causes the numbers to delay:
data = footage("example.json").sourceData;
rampTime = 3;
done = false;
i = t = tPrev = 0;
while (t <= time){
tPrev = t;
t += rampTime + parseFloat(data[i].duration)/ .4;
i++;
if (i >= data.length){
done = true;
break;
}
}
if (done){
parseFloat(data[data.length-1].slider);
}else{
if ((time - tPrev) < parseFloat(data[i-1].duration)/ .4){
parseFloat(data[i-1].slider);
}else{
v1 = parseFloat(data[i-1].slider);
v2 = parseFloat(data[i].slider);
t1 = parseFloat(data[i-1].duration)/ .4;
t2 = t1 + rampTime;
linear(time-tPrev,t1,t2,v1,v2);
}
}
If you can help find the solution please explain to me i am very new to coding and this is pretty complicated to me.Thank you!