text - How to Change Background Color on Processing? -


i'm still extremely new processing , i'm playing around right now. hoping find out how change background color between 2 colors, particularly between white , black, when click mouse. found code online has background color change between several different colors can't seem figure out how bg color can changed between 2 colors. particularly 'col+=' , 'col%=' represent because can't seem find in processing tutorial. please me! thank you! below code found.

void setup() {   size(600,400);   smooth(); colormode(hsb);  }  int col = 0; void draw() {   background(col,255,255);  }  void mousepressed(){ col+=20; col%=255; println(col); } 

"x += y" shorthand "x = x + y" and, likewise, "x %=y" shorthand "x = x % y" (where % modulo operator).

i'm going assume wanted ask "how change background 1 colour another, , again"; there's 2 based ways this.

1: set 2 (or more) reference colours, "current" colour, , change 'current' points to, drawing background off of that:

color c1 = color(255,0,0), c2 = color(0,0,255), current; void setup() { current = c1; } void draw() { background(current); } void mousepressed() { if(current==c1) { current = c2; } else { current = c1; }} 

every time click, program checks of 2 colours "current" points to, , instead points other colour.

2: set 1 colour, , apply operation modulo in 1, or 2, or ... steps:

color c = color(255,0,0); void draw() { background(c); } void mousepressed() { c = color( red(c), (green(c)+50)%255, blue(c)); } 

every time click, colour "c" gets green component increased 50, , modulo-corrected 255. it'll cycle through: 0, 50, 100, 150, 200, 250, 300%255=45, 95, 145, 195, 245, 295%255=40, 90, etc.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -