Processing 3.3.7 中 textSize() 的最大值
Maximum value for textSize() with Processing 3.3.7
我实际上是在尝试用 Processing 3.3.7
绘制一个大消息,但是 textSize()
函数没有按预期工作。草图是空的。
void setup()
{
size(600, 600);
background(0);
fill(#CC0000);
textSize(150);
text("Yeah!", width/2, height/2, 80, 80);
}
为什么?
发生这种情况的原因是 text
的定义是这样的:
text(str, x1, y1, x2, y2)
- x1 float: by default, the x-coordinate of text, see rectMode() for more info
- y1 float: by default, the y-coordinate of text, see rectMode() for more info
- x2 float: by default, the width of the text box, see rectMode() for more info
- y2 float: by default, the height of the text box, see rectMode() for more info
您选择的文本框(80, 80
)的宽度和高度太小,无法显示字体大小的文本150
,增加文本框的宽度和高度会使更大的文本也会出现。
此外,如果您想将文本居中(width/2
是绘图的 x 起点),您应该将其减去一半 textWidth
以补偿文本的大小。
为了补偿高度,“添加 textAscent() 和 textDescent() 值将为您提供线条的总高度。”source。
text("Yeah!", width/2-textWidth("Yeah!")/2,
height/2-(textAscent() + textDescent())/2, 150, 150);
我实际上是在尝试用 Processing 3.3.7
绘制一个大消息,但是 textSize()
函数没有按预期工作。草图是空的。
void setup()
{
size(600, 600);
background(0);
fill(#CC0000);
textSize(150);
text("Yeah!", width/2, height/2, 80, 80);
}
为什么?
发生这种情况的原因是 text
的定义是这样的:
text(str, x1, y1, x2, y2)
- x1 float: by default, the x-coordinate of text, see rectMode() for more info
- y1 float: by default, the y-coordinate of text, see rectMode() for more info
- x2 float: by default, the width of the text box, see rectMode() for more info
- y2 float: by default, the height of the text box, see rectMode() for more info
您选择的文本框(80, 80
)的宽度和高度太小,无法显示字体大小的文本150
,增加文本框的宽度和高度会使更大的文本也会出现。
此外,如果您想将文本居中(width/2
是绘图的 x 起点),您应该将其减去一半 textWidth
以补偿文本的大小。
为了补偿高度,“添加 textAscent() 和 textDescent() 值将为您提供线条的总高度。”source。
text("Yeah!", width/2-textWidth("Yeah!")/2,
height/2-(textAscent() + textDescent())/2, 150, 150);