Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Created April 18, 2015 06:12
Show Gist options
  • Save jhurliman/ec9f852cdc1fbaeca228 to your computer and use it in GitHub Desktop.
Save jhurliman/ec9f852cdc1fbaeca228 to your computer and use it in GitHub Desktop.
UIColor Linear Interpolation (lerp)
+ (UIColor *)colorLerpFrom:(UIColor *)start to:(UIColor *)end withProgress:(CGFloat)t
{
// TODO: Interpolate in HSB space instead of RGB
t = MAX(0, MIN(1, t));
CGFloat redA, greenA, blueA, alphaA;
[start getRed:&redA green:&greenA blue:&blueA alpha:&alphaA];
CGFloat redB, greenB, blueB, alphaB;
[end getRed:&redB green:&greenB blue:&blueB alpha:&alphaB];
CGFloat r = lerp(redA, redB, t);
CGFloat g = lerp(greenA, greenB, t);
CGFloat b = lerp(blueA, blueB, t);
CGFloat a = lerp(alphaA, alphaB, t);
return [UIColor colorWithRed:r green:g blue:b alpha:a];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment