# Using println to show a random color that's picked

**URL:** <https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367>\
**Category:** Coding Questions\
**Created:** [December 30, 2021, 12:05am UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367 "2021-12-30T00:05:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsco](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jsco](https://discourse.processing.org/u/jsco)\
**Post date:** [December 30, 2021, 12:05am UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367/1 "2021-12-30T00:05:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [December 30, 2021, 12:09am UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367/2 "2021-12-30T00:09:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jsco](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jsco](https://discourse.processing.org/u/jsco)\
**Post date:** [December 30, 2021, 12:19am UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367/3 "2021-12-30T00:19:03Z")

</div>

That’s what I needed. Thank you

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 30, 2021, 1:25am UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367/4 "2021-12-30T01:25:51Z")

</div>

Hello,

You can also print the hexadecimal representation:

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

```

Reference:

> **[Reference](https://processing.org/reference/color_datatype.html)**
>
> Datatype for storing color values. Colors may be assigned with get() and color() or they may be specified directly using hexadecimal notation such as #FFCC00 or 0xFFFFCC00.…

`:)`

---

<div class="post-metadata">

**Author:** ![jsco](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jsco](https://discourse.processing.org/u/jsco)\
**Post date:** [January 2, 2022, 4:38pm UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367/5 "2022-01-02T16:38:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 3, 2022, 10:06pm UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367/6 "2022-01-03T22:06:31Z")

</div>

That’s possible

Maybe this is a starting point for you: [Reference / Processing.org](https://processing.org/reference/JSONArray.html)

---

<div class="post-metadata">

**Author:** ![jsco](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jsco](https://discourse.processing.org/u/jsco)\
**Post date:** [January 25, 2022, 9:06pm UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367/7 "2022-01-25T21:06:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 25, 2022, 9:31pm UTC](https://discourse.processing.org/t/using-println-to-show-a-random-color-thats-picked/34367/8 "2022-01-25T21:31:32Z")

</div>

You checked the link

Here is the gist of it

```auto
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
