View on GitHub

pyxstitch

Download this project as a .zip file Download this project as a tar.gz file

pyxstitch

pyxstitch is an application (and associated library/compenents) that takes source code files/text and can produce syntax-highlighted patterns for cross stitching

How does it work?


pyxstitch receives input (via file or stdin) and uses the awesome pygments library to get syntax/coloring information. From there it reads through the input token stream and uses pillow and webcolors to handle image generation and color coding. Color codes are then passed off to a "closest" match RGB against the DMC floss colors (in 'floss.py'). This results in a grid-layout of stitching symbols and associated legend with color/symbol mappings.

Why?


There are some very useful applications (e.g. kxstitch) that can be used to generate patterns from images and event produce text blocks. But how do you take code/syntax highlighting and convert it? A screenshot of your editor and sending that into the application? Why not skip the clunky step and just pass code/flat files (with whitespace preservation) and have it handle the text layout for you without any strange mangling and some amount of consistency! Seriously, though, this is a melding of 2 generalized hobbies for me.

Examples!

Hello World (python)

The following code fragment in python
        vim hello_world.py
---
def main():
    print("hello world")

if __name__ == "__main__":
    main()

Just pass this into pyxstitch
pyxstitch --file hello_world.py

Which produces a pattern that can be cross stitched into this! hwpy

Hello World (C)

The following code fragment in C
        vim hello_world.c
---
#include <stdio.h>

int main()
{
    printf("hello world");
}

Passed into pyxstitch
pyxstitch --file hello_world.c

Which produces a pattern that can be cross stitched into this! hwpy