Home > OS >  Is there a way to give text a background color
Is there a way to give text a background color

Time:05-28

Is there a way to give text() a background color?

Example Code:

text("Hello",20,20);

I want there to be a background color to this text.

Could someone please help me with this

EDIT: The text() method is in draw()

CodePudding user response:

One technique is to place your text in a rectangle, ie text(str, x,y,w,h); and use fill() to set the text and background colors:

color BLUE = color(64, 124, 188);

PFont font;

void setup() {
  size(400, 200);
  background(255);
  font = createFont("Arial", 18);
}

void draw() {
  fill(BLUE); // background color
  rect(60, 50, 300, 80);
  textSize(24);
  textAlign(CENTER, CENTER);
  fill(255); //text color
  text("Jeremiah was a bullfrog.", 60, 50, 300, 80);
}

  • Related