Chess color change

Hello there, Iam supposed to color some quads to make a chequered image. By the way something is wrong with my code. Method cambioColor isn't working can you help me?

void setup(){ size(800,600); Chess(); }

void Chess(){ boolean cColor=true; for(int i=1;i<9;i++){ for(int j=1;j<9;j++){ cambioColor(cColor); DibujarRect(i50,j50); cColor=!cColor; } cambioColor(cColor); cColor=!cColor; } }

void DibujarRect(int x,int y){ rect(x,y,50,50); }

void cambioColor(boolean x){ String s1=""; s1 = Boolean.toString(x); if(s1.equals(true)){ color crema= color(249,252,148); fill(crema); }else{ color cafe=color(#583C09); fill(cafe); } }

Tagged:

Answers

  • Answer ✓

    There is no need for the Boolean / String conversion. Your code works just fine if you use x directly:

    void cambioColor(boolean x) {
      if (x) {
        color crema= color(249, 252, 148);
        fill(crema);
      } else {
        color cafe=color(#583C09);
        fill(cafe);
      }
    }
    
Sign In or Register to comment.