# Any way to access stored values of fill() outside of rect(), circle(), etc.?

**URL:** <https://discourse.processing.org/t/any-way-to-access-stored-values-of-fill-outside-of-rect-circle-etc/37631>\
**Category:** Coding Questions\
**Created:** [June 18, 2022, 7:07pm UTC](https://discourse.processing.org/t/any-way-to-access-stored-values-of-fill-outside-of-rect-circle-etc/37631 "2022-06-18T19:07:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Epsilon11](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@Epsilon11](https://discourse.processing.org/u/Epsilon11)\
**Post date:** [June 18, 2022, 7:07pm UTC](https://discourse.processing.org/t/any-way-to-access-stored-values-of-fill-outside-of-rect-circle-etc/37631/1 "2022-06-18T19:07:58Z")

</div>

Is there a way to get the current color values in a function? for example:

```auto
fill(255, 0, 80);
void function() {
    loadPixels();
    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = color( ***fill values*** );
    }
    updatePixels();
}

```

This is just an example but I want to know if there is a general way of getting the fill values

---

<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:** [June 18, 2022, 8:28pm UTC](https://discourse.processing.org/t/any-way-to-access-stored-values-of-fill-outside-of-rect-circle-etc/37631/2 "2022-06-18T20:28:17Z")

</div>

Hello,

It is not clear what you are asking…

Simple example using _get()_;

```auto
void draw() 
  {
  background(0x7F);
  int x = mouseX;
  int y = mouseY;
  fill(#DFFF00);
  circle(50, 50, 50);
  println(x, y, hex(get(x, y)));
  }

```

There are resources here to explore:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts…

`:)`

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 18, 2022, 8:29pm UTC](https://discourse.processing.org/t/any-way-to-access-stored-values-of-fill-outside-of-rect-circle-etc/37631/3 "2022-06-18T20:29:08Z")

</div>

Processing remembers the values used when the user calls the fill(…) method but does not provide methods for the user to retrieve them. Since the user is responsible for calling the fill(…) method then the user will already know these values e.g.  
`fill(255, 0, 80);`  
The user knows the values for the RGB channels so just store them in global variables e.g.

```auto
int r, g, b;
r = 255;
g = 0;
b = 80;
// then later on
fill(r,g,b);

```

The alternative is to override the fill method like I have done in this sketch

```auto
int fillR, fillG, fillB;

void setup() {
  size(320, 240);
  background(255);
  fill(255, 0, 80);
}

void draw() {
}

// Override fill method
void fill(int r, int g, int b) {
  println( fillR, fillG, fillB);
  fillR = r;
  fillG = g;
  fillB = b;
  // now call the Processing fill method
  super.fill( fillR, fillG, fillB);
}

void function() {
  loadPixels();
  for (int i = 0; i < pixels.length; i++) {
    pixels[i] = color( fillR, fillG, fillB );
  }
  updatePixels();
}

void keyPressed() {
  if (key == 'p') {
    function();
  }
}

```

---

<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:** [June 18, 2022, 8:38pm UTC](https://discourse.processing.org/t/any-way-to-access-stored-values-of-fill-outside-of-rect-circle-etc/37631/4 "2022-06-18T20:38:45Z")

</div>

> [@quark](#):
>
> Processing remembers the values used when the user calls the fill(…) method but does not provide methods for the user to retrieve them.

I did an exploration of this here and can retrieve the fill value:

> [@Are properties such as fill color, stroke weight, text size, etc. write only?](https://discourse.processing.org/t/are-properties-such-as-fill-color-stroke-weight-text-size-etc-write-only/33024/4):
>
> Hello, Some insight I have gleaned from topics and [Processing source code](https://github.com/processing): // Attributes Read // v1.0.0 // GLV 2021-10-22 //Defaults println(g.strokeWeight); println(g.textSize); println(hex(g.fillColor)); println(g.stroke); println(g.fill); //Test strokeWeight(1); println(g.strokeWeight); textSize(1); println(g.textSize); fill(0xFF00FF00); println(hex(g.fillColor)); noStroke(); println(g.stroke); noFill(); println(g.fill); slight_smile

I only found this useful for getting the default fill value.

`:)`

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 19, 2022, 6:45am UTC](https://discourse.processing.org/t/any-way-to-access-stored-values-of-fill-outside-of-rect-circle-etc/37631/5 "2022-06-19T06:45:26Z")

</div>

Hi @Epsilon11,

Just as you speak of _color values_(assume r,g,b), you can use the infos from [@glv](https://discourse.processing.org/t/any-way-to-access-stored-values-of-fill-outside-of-rect-circle-etc/37631/4) (g.fillColor) and apply the …

- [red(…)](https://processing.org/reference/red_.html)
- [green(…)](https://processing.org/reference/green_.html)
- [blue(…)](https://processing.org/reference/blue_.html)

…functions to it to get the single rgb values from a color.

ie:

```auto
int r = red(g.fillColor);
int g = green(g.fillColor);
int b = blue(g.fillColor);

```

Cheers  
— mnse
