String Art

23 Jul 2023

GitHubView repo

String Art

String and nail art generator

PythonArt4Fun

Generate string art from images using a greedy algorithm that simulates wrapping thread between nails on a circular board.

With the goal to generate such images: img

Algorithm

  1. Preprocess

    • Resize image
    • Convert to grayscale
  2. Initialize

    • Place nail_amount nails on a circle
    • Set per-nail connection limit
  3. Greedy Step

    • For all valid nail pairs:
      • Score line = sum of pixel intensities along line
    • Pick best line
    • Subtract intensity along that line
    • Update nail connection counts
  4. Repeat

    • Run for n iterations or until constraints are hit

Constraints

  • max_connections: max lines per nail
  • thread_length: total available thread
  • Pixel values are reduced and clamped ≥ 0