An algorithm for generating and displaying string art from an arbitrary image. String art is a way of constructing an image using only overlapping stright lines between fixed points around a circle and was a style pioneered by the artist Petros Vrellis. As a small experimental project I've created a greedy algorithm which achieves this conversion and created a simple CLI to let people experiment with it and generate their own art! Below is an example of the string art generated from a portrait of the actress Audrey Hepburn.
- Clone this repository
- Install dependencies:
pip install -e .This will install the convert_to_string command globally.
convert_to_string img.jpgThis will:
- Load
img.jpg - Generate string art with default parameters
- Save to
output.png(in whatever directory you are in)
convert_to_string portrait -o my_artwork.pngconvert_to_string audrey.jpg -o output.png -s 400 -p 512 -d 40| Option | Short | Default | Description |
|---|---|---|---|
img_path |
- | (required) | Input image name |
--output |
-o |
output.png |
Output image path |
--size |
-s |
1000 |
Output image size in pixels (square) |
--pegs |
-p |
200 |
Number of pegs around the circle |
--darkness |
-d |
50 |
Line darkness/opacity (0-255) |
--distance-weight |
- | 1.0 |
Weight for distance in line selection |
--darkness-weight |
- | 1.0 |
Weight for darkness in line selection |
String art works best when you are using it on images with certain properties, so to get the best outcomes try the code on images which...
- Do not contain tiny details
- Look good in greyscale
- Have most of their detail focused around the centre of the image
- Have low contrast
View all options:
convert_to_string --help