Search code examples
textrandomprocessingpointscurves

How to generate random points around the curves of characters using processing?


I would like to generate random/noise points along each character of a multiple line text. I've tried this with the Geomerative library, but unfortunately it does not support multi line. Any other solution?


Solution

  • You could find a library to get the path points of the text or if simply adding points, you could get a 2D snapshot(either using get() or PGraphics) of the text and fill in pixels. Here's a minimal example.

    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);
    }