@GoToLoop
I used color(175) just as an example, I was looking for the most general solution of saving a color generated using color()
.
Looks like those sketches save the colors as Hex Codes instead, which works to set RGB values, but not alpha values to my understanding.
As an alternative, I know that the color() method generates a color which is secretly stored as an integer, so I guess I could try to use color() in a blank sketch like this:
println(color(r,g,b,a)); // input whatever I want
copy the outputted integer, and then just directly save the integer into the static final color variable, and in that way I can use the color() method in whatever capacity I want (just not directly). For clarity within my class code, I can comment in what r/g/b/a values I used to generate the static color variable. So like this:
static final color c = 840423333; // color(23,215,165,50)
I think the main thing I’ve learned here is that I can’t directly use a non-static method (e.g., color()) in the definition of a static variable, so there needs to be a workaround that doesn’t use a non-static method.
But now I’m lost as to how to go about having other “default” properties for my classes that are more complex than color(), where I’m not sure what the workaround might look like. For example, I also wanted a default PShape for my class, that I would create with createShape()
but that’s a non-static method, so it doesn’t work.
// What I wish I could do... is there a workaround similar to what I did for color()?
static final PShape shape_DEFAULT = createShape(ELLIPSE,0,0,16,16);
Again, I can’t use a non-static variable because I’m trying to pass these “default” properties into overloaded constructors which rely on each other. And I can’t use a static variable because the methods I’m using (e.g., color(), createShape()) aren’t static.
Perhaps there’s some workaround to createShape() similar to color() where I can save the default value without needing to directly call the non-static method, but then that seems like an unsatisfactory solution, having to come up with workarounds for each new default thing I want that depends on a non-static method. It makes me think that I’m not properly organizing my code. Does anyone have other ideas?