Keep RGB Alive!

Hello,

The objective is to keep the sketch window populated with an even mix of R, G and B circles.

Start by moving your mouse over the initial colours and then try to keep up with any of the new circles to select the colours.

There is some colour blending of a small circular area where you select so you have to choose wisely!

Good luck!

// Keep RGB Alive!
// v1.0.0
// GLV 2021-08-10

// The objective is to keep the sketch window populated 
// with an even mix of R, G and B circles.

// Good luck!

void setup() 
  {
  size(600, 600);
  background(255);
  noStroke();
  }

void draw() 
  {
  loadPixels();  

  if (frameCount < 5*60)
    {
    fill(255, 0, 0);
    circle(width/4, height/2, 80);
    
    fill(0, 255, 0);
    circle(2*width/4, height/2, 80);
    
    fill(0, 0, 255);
    circle(3*width/4, height/2, 80);
    }
  
  int rad = 10;
  int xMin = mouseX - rad;
  int xMax = mouseX + rad;
  int yMin = mouseY - rad;
  int yMax = mouseY + rad;
  
  int redAve = 0;
  int greenAve = 0;
  int blueAve = 0;
  int count = 0;
  int colAve = 0;
  
  for (int x = xMin; x < xMax; x++) 
    {
    for (int y = yMin; y < yMax; y++) 
      {
      int loc = x + y * width;
      if (loc>0 && loc<pixels.length)
        {
        //if (dist(x, y, mouseX, mouseY) < rad)  
        if((x-mouseX)*(x-mouseX) + (y-mouseY)*(y-mouseY) < rad*rad)
          {
          count++;  
          //redAve += red(pixels[loc]);
          redAve += (pixels[loc]>>16) & 0xFF; 
          //greenAve += green(pixels[loc]);
          greenAve += (pixels[loc]>>8) & 0xFF; 
          //blueAve += blue(pixels[loc]);
          blueAve += (pixels[loc]>>0) & 0xFF; 
          
          //colAve = color(redAve/count, greenAve/count, blueAve/count);
          colAve = 0xFF000000 | (redAve/count)<<16 | (greenAve/count)<<8 | (blueAve/(count));
          }   
        }
      }
    }
   
  fill(colAve);
  circle(random(width), random(height), random(10, 40));   
  }

:)

3 Likes