我想沿多行文本的每个字符生成随机/噪声点。我已经用几何库尝试过这个,但不幸的是它不支持多行。还有其他解决方案吗?
问问题
325 次
1 回答
0
您可以找到一个库来获取文本的路径点,或者如果只是添加点,您可以获得文本的 2D 快照(使用get()或PGraphics)并填充像素。这是一个最小的例子。
PImage snapshot;
int randomSize = 3;
void setup(){
//render some text
background(255);
fill(0);
textSize(40);
text("Hello",0,50);
//grab a snapshot
snapshot = get();
}
void draw(){
int rx = (int)random(snapshot.width);//pick a random pixel location
int ry = (int)random(snapshot.height);//you can pick only the areas that have text or the whole image bot a bit of hit&miss randomness
//check if it's the same colour as the text, if so, pick a random neighbour and also paint it black
if(snapshot.get(rx,ry) == color(0)) snapshot.set(rx+((int)random(randomSize,-randomSize)),ry+((int)random(randomSize,-randomSize)),0);
image(snapshot,0,0);
}
于 2013-08-04T21:07:46.597 回答