Page 1 of 1
Colour Control Key Frames
Posted: September 22nd, 2015, 10:59 am
by dlewyb
Hi,
I'm trying to link up several Expression Control / Color Controls to keyframes on the colour value of an object.
key(1).time = effect("Color 1")("Color");
key(2).time = effect("Color 2")("Color");
key(3).time = effect("Color 3")("Color");
key(4).time = effect("Color 4")("Color");
What's the next step to get this to work?
Any help would be great, thanks!
Cheers,
Daniel
Re: Colour Control Key Frames
Posted: September 22nd, 2015, 11:23 pm
by beginUndoGroup
The things on left hand side are defined by the keyframes and cannot be overwritten, at least not explicitely as you wrote it.
Beside, the left hand side is a time (number), while the right hand side is a color (array of 3+1 numbers), so it's also hard to understand what you want to achieve!
Xavier.
Re: Colour Control Key Frames
Posted: September 23rd, 2015, 1:10 am
by dlewyb
Hi Xavier,
I'd like to define the colour value array of each key frame of an animated color property with color control (expression controller effect).
Thanks
Re: Colour Control Key Frames
Posted: September 23rd, 2015, 3:41 am
by beginUndoGroup
Ah ok. This should work:
Code: Select all
if (numKeys<1){
value;
}
else{
idx1 = nearestKey(time).index;
if (key(idx1).time>time) idx1--;
idx2 = idx1+1;
if (idx1<1) idx1=1 else if (numKeys<idx2) idx2=numKeys;
val1 = effect("Color " + idx1)("Color").value;
val2 = effect("Color " + idx2)("Color").value;
linear(time, key(idx1).time, key(idx2).time, val1, val2);
};
Re: Colour Control Key Frames
Posted: September 25th, 2015, 3:44 am
by dlewyb
OOOH YEAHHH that is very cool!!!! I love how those few lines of very smart code can do so much!
Thanks heaps BUG!!! If you ever come to Melbourne I'll buy you a drink / food / AFL game.
Could I substitute another term for "linear" if I wanted the colours to change immediately rather than fading or interpolating between the values.
I did try "step" with no success.
Thanks so much for your help!
Cheers!
Re: Colour Control Key Frames
Posted: September 26th, 2015, 7:49 am
by beginUndoGroup
No there is no such function. In the notations above to get a step behaviour that would be just : val1
That is, replace the line with the linear thing with:
Code: Select all
if (myConditionForStepBehaviour){
val1;
}
else{
linear(time, key(idx1).time, key(idx2).time, val1, val2);
};
where myConditionForStepBehaviour (boolean) could be the value of a checkbox control for instance.
Edit, : if you dont need linear at all, this should be simpler (faster)
Code: Select all
if (numKeys<1){
value;
}
else{
k = nearestKey(time);
idx = (k.index>1 && k.time>time) ? k.index-1 : k.index;
try{effect("Color " + idx)("Color").value}catch(e){value;};
};
Re: Colour Control Key Frames
Posted: October 5th, 2015, 4:12 am
by dlewyb
Once again BUG sensational work! I don't know how to hook up the the check box control for linear / step option, but I'll go try to find out how as that would handy.
Is there an easy way to add a loopOut() function to this is expression?
Many thanks again!
Re: Colour Control Key Frames
Posted: October 6th, 2015, 8:23 am
by beginUndoGroup
HI,
this is another way using markers.
If you have the possibility to use markers (ie they are not busy for something else) i think it's better, it allows to queue colors in arbitrary order,
like Color 1 - Color 2 - Color 1 - Color 6 - Color 4, etc
Markers comment must be 1, or 2, or 3, etc (ie number) or, for the last marker only : *, to specify to loop out.
Any other comment will be interpreted as "1" (ie: the color will be Color 1, if the effect "Color 1" is found).
Xavier
Code: Select all
// Requires : layer markers to carry comments (numbers, same as the numbers of the color effects : Color 1, Color 2 etc)
// If the last marker comment is exactly "*", the color animation will loop out continuously.
// If there is a checkbox control called "Linear Color Transitions": possibility to do linear transitions between colors
function getVal(j){try{j = parseInt(m.key(j).comment); if (isNaN(j) || j<1) j=1; val = effect("Color "+j)("Color").value;}catch(e){val=value;}; return val;};
m = marker;
M = m.numKeys;
LOOP_OUT = M>0 && m.key(M).comment==="*";
numValues = LOOP_OUT ? M-1 : M;
if (numValues<2 || time<=m.key(1).time){
getVal(1);
}
else{
t = time;
if (LOOP_OUT){
t1 = m.key(1).time;
t2 = m.key(M).time;
if (t>=t2){t = t1+ ((t-t1)%(t2 - t1));};
};
idx1 = m.nearestKey(t).index;
if (t<m.key(idx1).time) idx1--;
if (LOOP_OUT && idx1===M) idx1 = 1;
val1 = getVal(idx1);
try{doLinear = effect("Linear Color Transitions")(1).value;} catch(e){doLinear=false};
if (doLinear){
idx2 = idx1===M ? idx1 : idx1+1;
val2 = getVal(idx2);
ease(t, m.key(idx1).time, m.key(idx2).time, val1, val2);
}
else{
val1;
};
};
Re: Colour Control Key Frames
Posted: October 8th, 2015, 8:37 pm
by dlewyb
Sensational work BUG. Thanks again. I'm going to message you.
Cheers
Daniel