Created
April 18, 2015 06:12
-
-
Save jhurliman/ec9f852cdc1fbaeca228 to your computer and use it in GitHub Desktop.
UIColor Linear Interpolation (lerp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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