Created
June 25, 2017 17:18
-
-
Save behreajj/c7d3c577ba058a429575b05de335357a to your computer and use it in GitHub Desktop.
Color Gradients 2-6
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
color evaluate(float percent) { | |
int sz = colors.size(); | |
if (sz == 0) { | |
return 0x00000000; | |
} | |
float diff; | |
float fraction; | |
ColorStop current; | |
ColorStop prev; | |
for (int i = 0; i < sz; ++i) { | |
current = colors.get(i); | |
if (percent < current.percent) { | |
prev = colors.get(i - 1 < 0 ? 0 : i - 1); | |
diff = prev.percent - current.percent; | |
fraction = diff == 0 ? 0 | |
: (percent - current.percent) / diff; | |
return lerpColor(current.clr, prev.clr, fraction); | |
} | |
} | |
return colors.get(sz - 1).clr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment