【发布时间】:2023-02-10 13:24:15
【问题描述】:
有没有办法给 text() 一个背景颜色?
示例代码:
text("Hello",20,20);
我希望这段文字有背景颜色。
有人可以帮我解决这个问题吗
编辑: text() 方法在 draw()
【问题讨论】:
标签: java text background processing
有没有办法给 text() 一个背景颜色?
示例代码:
text("Hello",20,20);
我希望这段文字有背景颜色。
有人可以帮我解决这个问题吗
编辑: text() 方法在 draw()
【问题讨论】:
标签: java text background processing
一种技术是将文本放在一个矩形中,即 text(string, x,y,w,h);并使用 fill() 设置文本和背景颜色:
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);
}
【讨论】: