This started with a text from my aunt. She wanted me to replicate an effect found here.
The premise of this art is that each sentence is broken down and saved as the sum of the contained words - e.g. the sentence “This is a wonderful day!” will be saved as 5
for our program. The Path will move in a given direction for that length, and then turn 90 degrees to the left. Any time you see a long unbroken sentence, you can be sure the author has been letting their thoughts (and pens) wander.
Here’s the end result for two of her books.
There were a few distinct problems to solve. I have detailed them below. All of the code and example images are here: https://github.com/daviseford/word-art
Well, what’s a sentence? Luckily, I didn’t need to concern myself too deeply with that idea. I used the Natural Language ToolKit library for Python and went about tokenizing input text. This was easier than I imagined:
Now we’ve got a list of sentence lengths. We combine that with a little geometry, the wonderful svgpathtools
, and some good old fashioned computing.
The end result is a script that takes in a filepath (a plaintext file), and optionally a color parameter for the generated line.
The script’s argument structure means I get to run commands like:
python svg.py -f ./txt/romance_of_lust.txt --color "red"
python svg.py -f ./txt/wizard_of_oz.txt --color "yellow"
Well, that’s a lot of code you don’t care about. How about some pictures?
All of the below images are generated from the text provided by Project Gutenberg. I used a selection of their Top 100 books.
I hope this isn’t too much for you - here’s this article.