我想沿着多行文本的每个字符生成随机/噪声点。我在Geomative库中尝试过,但不幸的是,它不支持多行。还有其他解决方案吗?
您可以找到一个库来获取文本的路径点,或者如果只是添加点,您可以获得文本的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);
}