Closed Tone60 closed 6 years ago
The #
character is not part of a hex number.
If all you're doing with that string is setting a fill color, then Python Mode lets you just use a web color spec like the one you already have.
fill("#FFCC00")
If you have some string that starts with #
, then you can unhex a "slice" of that string that doesn't have the first character.
hx = "#FFCC00"
num = unhex(hx[1:])
I've tried your solution, but i still get an error; "Syntax error,; may be missing a ']' character? "num = unhex(hx[1:]) treats the hx variable as a real array. I do appreciate your help with this seemingly easy CSC exercise. Thanks.
void setup(){ size(600,460); background(255);
}
void draw(){
int num=0; String hx="#FFCC00";
num = unhex(hx[1:]); fill(num); ellipse( 100,200,60,60); }
This site is for bugs in Python Mode, but you seem to be writing Java.
Thanks, i've opted for manually removing the # character and your suggestion works. Thanks for the info. Much appreciated.
I have tried passing hexadecimal values through an array, but it generate an error; Then I tried the simplest approach as you see on the code below, and it still generates the same error "NumberformatException: For input string: "#FFC000" ". Anyone has any ideas?
Thanks
void draw(){ String hx ="#FFC000";