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

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

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

Hello,

It is not clear what you are asking…

Simple example using get();

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:

:)

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.

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

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();
  }
}

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

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

:)

1 Like

Hi @Epsilon11,

Just as you speak of color values(assume r,g,b), you can use the infos from @glv (g.fillColor) and apply the …

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

ie:

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

Cheers
— mnse