how do i get the current color of background()?

edited July 2014 in How To...

I would like to put a loop in my code that checks the background color so that it changes depending on what color it currently is.

How do I do that?

Answers

  • Answer ✓

    when you set background, save the value you set.

    color bkColorGlobal; 
    
    void setup() {
      setBkColor ( color(176, 222, 22) );
      println ("Color: "+colorAsString(bkColorGlobal)+".");
    }
    
    void draw () {
      //
    }
    
    void setBkColor (color bkColLocal) {
      bkColorGlobal = bkColLocal;
      background(bkColLocal);
    }
    
    String colorAsString (color bkColLocal) {
      return int(red(bkColLocal))+ ":" + 
        int(green(bkColLocal) )+ ":" + 
        int(blue(bkColLocal));
    }
    //
    
Sign In or Register to comment.