captcha-canvas API Documentation - v3.3.4
    Preparing search index...

    Function getRandomCoordinate

    • Calculates evenly distributed coordinate positions for CAPTCHA characters.

      Generates an array of [x, y] coordinates that distribute characters evenly across the canvas width while adding random vertical positioning for security. The coordinates are sorted by x-position to ensure proper left-to-right ordering.

      Parameters

      • height: number

        Canvas height in pixels

      • width: number

        Canvas width in pixels

      • size: number

        Number of character positions to generate

      Returns number[][]

      Array of [x, y] coordinate pairs

      const positions = getRandomCoordinate(100, 300, 6);
      // Returns: [[30, 45], [80, 67], [130, 23], [180, 78], [230, 34], [280, 56]]
      const coordinates = getRandomCoordinate(150, 400, 8);
      const text = 'SECURITY';

      coordinates.forEach(([x, y], index) => {
      ctx.fillText(text[index], x, y);
      });