q5play
    Preparing search index...

    Function textToPoints

    • 📘 Converts a string of text to an array of points.

      Samples opaque pixels in a text image made with createTextImage.

      It's influenced by text settings, such as font, size, and alignment.

      Uses a Z-order curve to improve spatial distribution, which preserves the shape of text better than purely random sampling.

      Parameters

      • str: string

        string of text

      • Optionalx: number

        x coordinate of the text position

      • Optionaly: number

        y coordinate of the text position

      • OptionalsampleRate: number

        lower values increase dithering (1 = all points, 0.1 = ~10% of points)

      • Optionaldensity: number

        pixel density of the text

      Returns []

      await Canvas(200);
      textSize(220);
      textAlign(CENTER, CENTER);

      let points = textToPoints('5');

      for (let pt of points) {
      rect(pt.x, pt.y, 5, 20);
      }
      await Canvas(200, 296);
      textSize(340);
      noFill();
      stroke(1);
      strokeWeight(8);

      let pts = textToPoints('q', -100, 56);

      strokeWeight(1);
      for (let pt of pts) {
      ellipse(pt.x, pt.y, 10, 0.1);
      }