|
Author |
Topic: comparing colors (Read 617 times) |
|
der_rabe
|
comparing colors
« on: Feb 17th, 2004, 4:10pm » |
|
is there a way to compare colors. like: if whateverColor == referenceColor this does not work,but how can i do it?
|
Bernd Salewski student of digital media Hochschule Bremen
|
|
|
mKoser
|
Re: comparing colors
« Reply #1 on: Feb 17th, 2004, 4:55pm » |
|
this works: Code: color c1, c2; void setup(){ c1 = color(255, 0, 0); c2 = color(255, 0, 0); } void loop(){ } void mousePressed(){ if(c1 == c2){ println("colors match"); }else{ println("colors don't match"); } } |
| try changing the values of c1 and c2 (to not match) and run the code again. + mikkel
|
mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
|
|
|
der_rabe
|
ok
« Reply #2 on: Feb 17th, 2004, 6:25pm » |
|
so it works, ok, i guess i have to look into my code again, to find out, why it does not work as a want it to. my head is soo dumb today (got a cold, haatschii!)
|
Bernd Salewski student of digital media Hochschule Bremen
|
|
|
rgovostes
|
Re: comparing colors
« Reply #3 on: Feb 18th, 2004, 5:37am » |
|
A color is just a 4 byte integer, isn't it? You should be able to do comparisons like > and <= if you were so inclined.
|
|
|
|
benelek
|
Re: comparing colors
« Reply #4 on: Feb 19th, 2004, 11:47am » |
|
a color (as in the data type color) is a 32-bit integer (just like an int). the 32 bits are divided up into four lots of 8 bits, in order to store color component information. it works like this: Code: AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB //A = Alpha //R = Red //G = Green //B = Blue |
| and of course, an 8-bit number goes from 0 to 256, which is why you define your RGB numbers in components within that range. because the components are stored in bit locations rather than in some decimal fashion, you can't use >= or <= on the whole color variable. however, if you know how to use bit-shifting to get to the components, you can use >= or <= on those RGB components. if you don't know what the hell i'm on about, you can use the red(), green() and blue() methods to look at the color components hopefully helpful, ~Jacob
|
|
|
|
|