如何使用处理在字符曲线周围生成随机点?

时间:2013-08-04 14:44:59

标签: text random processing points curves

我想在多行文本的每个字符上生成随机/噪点。我已经尝试使用Geomerative库,但不幸的是它不支持多行。还有其他解决办法吗?

1 个答案:

答案 0 :(得分: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);
}