Skip to main content

String Art

A Python library to explore string art.

String art with three layers of threads

Install

pip install stringart

Requires Python 3.9 or later.

Quick Start

from stringart import *

make_circle(18)

for i in range(18):
    connect(i, i+6)

show()
18 points, each connected to the point 6 steps ahead

show() displays the art in a Jupyter notebook. In a plain Python script, use save("art.svg") to save it as an svg file instead.

Functions

Function What it does
make_circle(n) Starts a new art with n points on a circle, numbered 0 to n-1.
connect(a, b) Connects point a to point b with a thread.
show() Displays the art in Jupyter.
save(path) Saves the art as an svg file.

Point numbers wrap around the circle. With 18 points, connect(17, 20) is the same as connect(17, 2). That is why connect(i, i+6) works for every i in the loop above.

Examples

pentagon.py pentagonal-star.py radials.py

See the examples directory for the programs. To regenerate the svg files after changing them, run make in that directory.

Why

StringArt was born out of a desire to teach programming to beginners in a fun, interactive way.

Every program draws a picture, so students see right away what their code does, and a mistake looks wrong instead of just printing a wrong number.

The API has just four functions, but the possible complexity is far from small. Connecting each point by hand quickly becomes tedious, and the need for a loop comes naturally. When the same pattern shows up again and again, the need for a function follows. Ideas like generalization and abstraction, which are hard to convey, emerge on their own in this medium.

Development

uv sync
make -C examples
uv build

License

MIT. See LICENSE.

Release files for stringart 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stringart 0.1.0
File Size Uploaded
stringart-0.1.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stringart 0.1.0
File Interpreter ABI Platform
stringart-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / stringart-0.1.0.tar.gz

Download URL stringart-0.1.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0f4df34c9d005d2239d192dd9387ead8b3a09e165acf32ecaf1ae19a4c556437
BLAKE2b-256 checksum
How to use checksums
8450afc9189d87434f7f595e21be57c2471fe21104d0fd8d651a02ca162c579c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / stringart-0.1.0-py3-none-any.whl

Download URL stringart-0.1.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3acf5a4e6b941468c99631569ab735a5adf1d179d0908bad1232d7123533565a
BLAKE2b-256 checksum
How to use checksums
897b74c9fe0c44cabcaa62846f1cafe4f18fbf9840babc36885e3b4a0b7df8c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page