Sort Colours by brightness?

edited April 2014 in How To...

Hello,

I am wondering if it is possible to sort colours by their brightness. I am using the following code to get the colour of 5 random pixels from the webcam. I then want to be able to arrange these colours so that for example:

if (x == y) { fill (colour A) }

else if (x == x) { fill colour B) { }

etc..

the code i am using is:

void draw () {

  if (cam.available() && hasReadColors == false) { 
    cam.read(); 
    for (int i = 0; i< colors.length; i++) {
      colors[i] = cam.get((int)random(width), (int)random(height));
    }
    hasReadColors = true;
  } 

  colorA = colors [0];
  colorB = colors [1];
  colorC = colors [2];
  colorD = colors [3];
  colorE = colors [4];

}
Tagged:

Answers

Sign In or Register to comment.