Why isn't my text fill changing?

edited April 2016 in Questions about Code

Every time i try to change the colour of my text it doesn't show up

float scale;

void setup() {
  size(640, 360);
  noStroke();
  scale = width/20;
}

void draw() {
  for (int i = 0; i < scale; i++) {
    colorMode(RGB, (i+1) * scale * 10);
    fill(millis() % ((i+1) * scale * 10));
    rect(i*scale, 0, scale, height);
  }

  textSize(100);
  fill(0);
  text("TURN", 0, 230);
  fill(126);
  text("BACK", 0, 150);
  fill(255);
  text("TIME", 0, 70);
}

Answers

  • You change the colorMode on line 11. This change persists, which means that color(0), color(126), and color(255) are not the black, grey, and white that you are used to.

    Here is one way to fix it:

    float scale;
    
    void setup() {
      size(640, 360);
      noStroke();
      scale = width/20;
    }
    
    void draw() {
      background(255,0,0);
    
      pushStyle();
      for (int i = 0; i < scale; i++) {
        colorMode(RGB, (i+1) * scale * 10);
        fill(millis() % ((i+1) * scale * 10));
        rect(i*scale, 0, scale, height);
      }
      popStyle();
    
      textSize(100);
      fill(0);
      text("TURN", 0, 230);
      fill(126);
      text("BACK", 0, 150);
      fill(255);
      text("TIME", 0, 70);
    }
    

    Changing the colorMode() back to the default values would be another.

  • Thank you! How do you change colorMode back to the default values? (sorry, I'm new to this)

  • The default is colorMode(RGB, 255);

  • Thank you! :)

  • Like this?

    float scale;
    
        void setup() {
          size(640, 360);
          noStroke();
          scale = width/20;
        }
    
        void draw() {
          for (int i = 0; i < scale; i++) {
            colorMode((RGB, 255), (i+1) * scale * 10);
            fill(millis() % ((i+1) * scale * 10));
            rect(i*scale, 0, scale, height);
          }
    
    
          textSize(100);
          fill(0);
          text("TURN", 0, 70);
          fill(126);
          text("BACK", 0, 150);
          fill(255);
          text("TIME", 0, 230);
        }
    
  • Don't worry, I used the Pushstyle, Popstyle to it. Thank you guys so much! :)

Sign In or Register to comment.