Using println to show a random color that's picked

Hi, I have set println for some different number variables and I have it working just fine. But I have a color picker set up as such;
<
int selected = (int)random(0, 20);
int choicesR[] = {51, 12, 25, 18, 33, 5, 15, 7, 8, 251, 252, 254, 255, 245, 254, 233, 100, 142, 239, 5};
int choicesG[] = {52, 13, 26, 21, 33, 5, 15, 8, 8, 252, 252, 255, 255, 245, 255, 255, 194, 255, 124, 255};
int choicesB[] = {50, 6, 20, 0, 33, 0, 15, 3, 8, 242, 250, 242, 255, 245, 245, 38, 255, 235, 255, 52};
color r2 = color(choicesR[selected], choicesG[selected], choicesB[selected]);
/>
And the println(r2) for this example gives me a big negative number output. What would be the move to get it show me the rgb value?

Also, is this the best way to have the metadata for an image?

I appreciate the help.

Color variables are really just numbers. Try printing the values of red(r2), green(r2), and blue(r2) instead.

1 Like

That’s what I needed. Thank you

Hello,

You can also print the hexadecimal representation:

color col = color(0, 128, 255);
println(hex(col));

Reference:

:)

Hi, so I was able to get the println how I was thinking.

But I maybe should have asked a different question.

Is there a way to print those values into a json file when a png is generated?

That’s possible

Maybe this is a starting point for you: Reference / Processing.org

Hi, I’ve been studying up on json and trying to learn. I have a general understanding of what I need to do, but also feel somewhat lost how to really implement.

So for the output I am trying to make, I have a bunch of random variables that will yield different numbers in the different outputs. So for example, I’d want the json to be something like variable1 = x and shows that number value for x. Does that make sense?

1 Like

You checked the link

Here is the gist of it

JSONArray values;

void setup() {

  values = new JSONArray();

  for (int i = 0; i < species.length; i++) {

    JSONObject animal = new JSONObject();

    animal.setInt("id", i);
    animal.setString("species", species[i]);
    animal.setString("name", names[i]);

    values.setJSONObject(i, animal);
  }

  saveJSONArray(values, "data/new.json");

Here animal.setInt(“id”, i);

you could simply store your color