jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

unhexing a string to decimal representation #203

Closed Tone60 closed 6 years ago

Tone60 commented 6 years ago

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";

    int temp = unhex(hx);

fill(temp);
ellipse(100,300, 60, 60);

}
jdf commented 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:])
Tone60 commented 6 years ago

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); }

jdf commented 6 years ago

This site is for bugs in Python Mode, but you seem to be writing Java.

Tone60 commented 6 years ago

Thanks, i've opted for manually removing the # character and your suggestion works. Thanks for the info. Much appreciated.