In the realm of computer-generated string art, designs generally fall into two categories: pure geometric patterns based on math formulas, and photo portraits calculated using image optimization loops. While both are wound on circular boards, their core programming paradigms represent completely different branches of mathematics.
1. Parametric Curves and Modular Multiplication
Geometric string art relies on modular arithmetic to establish connection guidelines. The nails are numbered from 0 to N-1. To generate a curve, the algorithm applies a multiplier (M) to each nail index (i) and draws a line to the resulting index modulo N. This formula is written as: f(i) = (i * M) mod N.
Depending on the multiplier value chosen, beautiful geometric curves emerge along the chord intersections:
- M = 2 (Cardioid): A heart-shaped envelope curve containing a single cusp.
- M = 3 (Nephroid): A kidney-shaped curve with two cusps.
- M = 4 (Trifolium): A three-cusped geometric envelope resembling a leaf.
- Hypotrochoids: Generated by rolling a small circle inside a larger boundary circle, creating complex multi-pointed stars.
2. Image Reconstruction via Linear Optimization
In contrast, portrait generators like Stringify do not follow pre-set mathematical equations. Instead, they use a raster image as their target goal and calculate paths dynamically. The generator does not know what shapes it is drawing; it only knows how to minimize color discrepancies in a grayscale pixel buffer.
Because portrait generation requires fitting lines to arbitrary shades, it is solved using iterative feedback. In math terms, this is a linear approximation problem. By drawing a line and subtracting its darkness from the image, we guide subsequent lines to other dark coordinates.