Ok, so it turns out I hadn’t solved my own problem after all–mainly because it’s not just the opacity expression I need; I also need to time remap a random freeze frame and a random colour change (from a set palette) at the same time as the fade up / fade down–basically a new frame / colour every time opacity reaches zero. On top of that, a second layer also needs to randomly change colour over the same period as fade up / fade down.
I’ve confused myself with all of that–and it’s my project! Maybe an actual description will help…
I have a set of icons (currently 38, but could increase), all 1 frame in length, in a 38 frame precomp. Around that precomp is a border. I want to randomly select a frame from the icon precomp and hold on it for a set amount of time (ideally set by a slider in a master comp) and have it fade out over a set time (again on a slider) then change frame and colour (via a Tint / Fill effect) then fade up again (same as fade out time). Meanwhile the border will, as the icon fades out / in, change from one random colour to another (without fading in / out).
I have some of this working–but can’t get the timing of each change to coincide, even though the timings are all supposedly linked to the same master sliders…
Current fade in/out code (this seems to work as I want it to):
fadeTime = framesToTime(comp("MAIN COMP").layer("TIMING CONTROLS").effect("Fade In/Out Time (Frames)")("Slider"));
seedRandom(comp("MAIN COMP").layer("TIMING CONTROLS").effect("Random Seed")("Slider"), true);
onTime = framesToTime(comp("MAIN COMP").layer("TIMING CONTROLS").effect("On Time (Frames)")("Slider"))*random(1,2);
fadeDur = fadeTime*2+onTime;
t = time%fadeDur;
fadeInOpacity = linear(t, inPoint, inPoint+fadeTime, 0, 100);
fadeOutOpacity = linear(t, fadeTime+onTime, fadeDur, 100, 0);
(fadeInOpacity * fadeOutOpacity) / 100
Time remap code (works, but timing is off with above opacity change):
segDur = comp("MAIN COMP").layer("TIMING CONTROLS").effect("On Time (Frames)")("Slider")/25+comp("MAIN COMP").layer("TIMING CONTROLS").effect("Fade In/Out Time (Frames)")("Slider")/25;
minVal = inPoint;
maxVal = framesToTime(37);
seed = Math.floor(time/segDur);
seedRandom(seed,true);
random(minVal,maxVal);
Colour change (this, again, works, but timing doesn't match--works well as transition for border, but not for icon colour change):
colors = [[49,32,28,255]/255,
[0,175,170,255]/255,
[221,0,49,255]/255,
[172,0,51,255]/255,
[255,108,27,255]/255,
[220,143,27,255]/255];
easeTime = framesToTime(comp("MAIN COMP").layer("TIMING CONTROLS").effect("Fade In/Out Time (Frames)")("Slider"));
segDur = framesToTime(comp("MAIN COMP").layer("TIMING CONTROLS").effect("On Time (Frames)")("Slider"))*2;
curSeg = Math.floor(time/segDur);
t = time%segDur;
seedRandom(curSeg,true);
idx1 = Math.floor(random(colors.length));
seedRandom(curSeg-1,true);
idx0 = Math.floor(random(colors.length));
ease(t,0,easeTime,colors[idx0],colors[idx1])