I’d like to break up a string of color values and then return it (so I can then use it in my stroke function).
However, when I run the following, my code will not render.
color colorDeterminer(int class) {
color c = #FFFFFF;
String colors = "#EF8AB3,#DE91C4,#C89AD1,#AEA2DA,#90AADD,#70B1DB,#4FB6D3,#30BAC6,#21BDB5,#2EBEA1,#47BE8C,#61BC77,#7AB963,#92B552,#A9B046,#BFA93F,#D3A241,#E59949,#F39157,#FD8968";
int[] colorsSplit = int(colors.split(","));
if (class > 700 && class < 710) {
c = colorsSplit[1];
}
}
Casting an array of Strings to an int() doesn’t make sense.
What you need to do is do some additional work on the array of Strings.
Loop over each string in turn. ("#A3B3C6")
Drop the leading # sign using substring() to get a new string that is only numbers and letters. (“A3B3C6”)
Then split that… and use unhex()…
You are not really converting the strings to integers. I think that it would be better to use Integer.parseInt(“String”) to do this. If not, Chrisir’s approach is also good.
I don’t really think that this approach works for hexes, because those are encoded. This approach would only work for strings that have integer numbers like “8” inside. The unhex() function that processing provides would be good enough. However, in order to decode all 3 integers of data inside the hex code, a better approach would be to split the string into 3 hexes of rgb values, add 4 or 6 0’s to the ends in order to make a rgb color. Then, maybe an unhex() would work to get all 3 values. An array of colors would be better if you don’t want to go through the ardrous process of decoding the hexadecimal.