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() {
    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = color(  ***fill values***  );

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


It is not clear what you are asking…

Simple example using get();

void draw() 
  int x = mouseX;
  int y = mouseY;
  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

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

int fillR, fillG, fillB;

void setup() {
  size(320, 240);
  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() {
  for (int i = 0; i < pixels.length; i++) {
    pixels[i] = color(  fillR, fillG, fillB  );

void keyPressed() {
  if (key == 'p') {

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.


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

— mnse