Loading...
Logo
Processing Forum

colorMode(3)???

in Programming Questions  •  3 years ago  
Hello,

I came across this neat little sketch over at openprocessing: http://www.openprocessing.org/visuals/?visualID=3867

int i,j;
void draw(){
  colorMode(3,250);
  filter(11);
  smooth();
  for(j=0;j<25;j++){
    fill(n(5),250,250);
    ellipse(n(0),n(9),n(40)/6,n(40)/6);
  }
  i++;
}
float n(int k){
  return noise(j+mouseX,k+mouseY,i*0.007)*350-15;
}


and I noticed that a couple of functions like colorMode() and filter() have numbers in their parameters. I thought these only worked if very specific parameters like 'RGB' or 'THRESHOLD' were used. What's going on here?

Replies(2)

Re: colorMode(3)???

3 years ago
What's happening here is that some of these parameters like RGB and THRESHOLD are actually integer variables with fixed values.  For example, it appears as though colorMode() takes a parameter like "RGB" or "HSB" as an argument, but it actually takes an integer--it's just that the integer variable RGB has been (permanently) assigned a specific value.

The following tiny program will demonstrate this:
Copy code
  1. void setup() {
  2.   println(RGB);  // prints "1"
  3.   println(HSB);  // prints "3"
  4. }


Re: colorMode(3)???

3 years ago
And it is a bad idea to use the numbers, unless you want to obfuscate your program: nothing prevents the Processing coders to change the numbers, or even the type of these constants! (eg. using enums)