Created
June 25, 2017 16:46
-
-
Save behreajj/ef29cc26be99205f42a827d588c148e4 to your computer and use it in GitHub Desktop.
Color Gradients 2-2
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
class Gradient { | |
ArrayList<ColorStop> colors = new ArrayList<ColorStop>(); | |
Gradient() { | |
} | |
Gradient(ColorStop... cs) { | |
for (int i = 0, sz = cs.length; i < sz; ++i) { | |
colors.add(cs[i]); | |
} | |
java.util.Collections.sort(colors); | |
} | |
Gradient(color... cs) { | |
int sz = cs.length; | |
float fsz = sz <= 1 ? 1 : float(sz - 1); | |
for (int i = 0; i < sz; ++i) { | |
colors.add(new ColorStop(i / fsz, cs[i])); | |
} | |
} | |
String toString() { | |
StringBuilder sb = new StringBuilder(); | |
for (int i = 0, sz = colors.size(); i < sz; ++i) { | |
sb.append(colors.get(i)); | |
if (i < sz - 1) { | |
sb.append(",\n"); | |
} | |
} | |
return sb.toString(); | |
} | |
void addColorStop(ColorStop cs) { | |
colors.add(cs); | |
java.util.Collections.sort(colors); | |
} | |
void addColorStop(float prc, int clr) { | |
addColorStop(new ColorStop(prc, clr)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment