I have to animate alpha of an element that is being calculated offline. Lets talk about the simple alpha animation. Alpha is zero, alpha grows to 1, stays a while and goes back to zero.
Something like the graph below:
The animations will have different times. I need something that I can give the time (t) and obtain the value (v).
This animation is to be put inside a
CABasicAnimation* fadeInOut = [CABasicAnimation animation];
fadeInOut.keyPath = @"filters.myFilter.inputRadius";
fadeInOut.fromValue = @(0);
fadeInOut.toValue = @(10);
fadeInOut.duration = 0.2f;
fadeInOut.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
fadeInOut.autoreverses = YES;
[self.layer addAnimation:fadeInOut forKey:nil]; // NO WAY!
CIFilter and animating... I presume that means your filter class takes a time parameter, and varies its result based on that?
If so, there are two options you could look into. Both rely on the fact that your desired timing curve looks like an "ease-in-ease-out" S-curve followed by that curve's reverse.
If you're writing CI Kernel Language code to implement your filter's effect, you can interpolate based on your time parameter using the
smoothstep function (that function is defined by GLSL, and CI Kernel Language is a superset of GLSL except where defined otherwise. Since you have a double S-curve, you'll need to do it twice:
// pseudo CI Kernel source: effect = smoothstep(0, 0.5, time) - smoothstep(0.5, 1, time)
If you're not writing a kernel, but instead implementing a filter in terms of other filters, you can define your own equivalent of the smoothstep function — that definition is well known and fairly simple, since it's in many graphics libraries. (Or you can learn about Hermite interpolation in general and go nuts with your own smoothing functions.) Then use your function to change the input to your internal filter based on your time parameter.