Skip to content

Instantly share code, notes, and snippets.

@behreajj
Created June 25, 2017 17:18
Show Gist options
  • Save behreajj/c7d3c577ba058a429575b05de335357a to your computer and use it in GitHub Desktop.
Save behreajj/c7d3c577ba058a429575b05de335357a to your computer and use it in GitHub Desktop.
Color Gradients 2-6
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