We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I have an excel spreadsheet with "6ef442", I load the string and put it into classColor[0], then here's where things get really stupid:
Tab1:
newEvent.coloring(classColor[0]);
Tab2:
void coloring(String chosen) {
classColor = unhex(chosen);
}
void draw() {
eventColor = createShape(RECT, 0, 0, 40, 40);
eventColor.setFill(classColor);
eventColor.setStroke(false);
}
No matter what obscure type of code I try, I cannot get that rectangle to turn 6ef442. Just... Help. If you know how to improve my ridiculous code or if you know how to get just my stupid rectangle to be the color I want it to be. I appreciate it a ton. Thank
Answers
we need a runnable example
classColor[0] - this is an element of an array called classColor
classColor - this is the whole array? another variable with the same name?
I'm not exactly sutr how to give a better runable example than that due to the way I've set up the script. And yes, sorry, the array is classColors[] and then I have a variable classColor that I JUST want to be my hexcode.
And what's chosen in that new example? Just a hex string? And classColor?
As runable examples go it's not very runable.
Is classColor an int (i.e. a color), as per the unhex reference page?
Thats the closest I could get to making a runable version.
As Jeremy points out, unhex() is designed for this.
The only catch is that you have no alpha specified. You probably want full alpha but are getting no alpha. So try appending "ff" before calling unhex or adding it to the colour after conversion.
doesn't the unhex example work as a runnable example?
you see an empty rectangle because there's no alpha in your hex string.
the fill() documentation suggests that changing that to
fill(hi, 255);
should work. but i found i had to usefill(0xff000000 | hi);
Ah, there seems to be a bigger problem with your use of parseInt
this prints 16, which is wrong.
it looks like parseInt is being overriden within processing. if you force the use of the java parseInt (a static method on Integer) then this is ok...
https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L9524
wtf! this is terrible.
I'm not sure if you're saying my code is terrible or the difficulty of my problem is terrible. Either way, you're right.
No, adding a function with the same name and signature as a standard Java method, like the processing authors did with parseInt, is terrible. It'll just cause problems like yours.
class
: Integer.parseInt().https://Processing.org/reference/unhex_.html
https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String,%20int)
processing should at least document their parseInt.
try it. this gives me a non-filled(?) rectangle.
public
&protected
stuff!https://Processing.org/reference/intconvert_.html
int
is a Java's reserved keyword. And thus it's invalid inside a ".java" file! :ar!Possibly relevant: unhex doesn't produce values that match the way RGB is packed into an int.
This sounds like an issue to report to either the Processing repo or the Processing-docs repo....
Color format bit logic demo/test, redux:
same thing. only color has automatically added 0xff000000 making it negative
@Tallen121 -- so, in summary:
Don't
unhex("6ef442")
. Instead, prepend ff (or whatever your alpha / transparency should be.Because unhex doesn't prepend ff, any 6-character hex string that you unhex and read as a color will have an alpha of 0 (the first two characters out of 8), and will be transparent. Prepend ff to see the color, as per the example on the unhex reference page:
If you want to use 6-character color hexes, for convenience, you could wrap that in a function :)
Thanks!