Diffusing a sentence. Let it expand and propagate in a somehow ‘electrical’ way.

Page three of the book.

Contribution for NaNoGenMo 2021. NaNoGenMo (National Novel Generation Month) is an annual event with the goal to write computer code that generates a novel of 50.000+ words.

This small program crops a portion of an image of a sentence ~60.000 times. The size of each piece is 1/12 of the sentence. After every cut the position where the ‘punch’ is put, moves left or right (on x-axis). The movement follows a sine wave. (See There is some frequency modulation going on. For making a book, the snippets are placed on a page: 10 per row, 30 rows per page. The order follows the time of cutting.

Input: A sentence taken from the introduction to Heinrich Hertz’ book on Electric Waves, 1893.

― Book, 202 pages  ↷ PDF (37 MB)

Code / Repository

ImageMagick 7 and Bash/Shell script


  until [ $bz -gt  60298 ] # 201 pages
    bx=`printf %05d $bz`
    hz=`awk -v x="$bz" 'BEGIN {wv=sin(sin(4*3.14159265*(x/1000))
      * 3*3.14159265*(x/2000 +1))+0.9999 ; printf wv }'`
    mkdir -p cuts # create directory for the snippets
    echo " Cutting … $bx"
    magick hzz.png -gravity SouthWest -crop
    "%[fx:(w/12)]"x"%[fx:h]"+"%[fx:(w/2.2)*$hz]"+0 +repage cuts/$bx.png

  while :
    echo ' Making new pages … '
    montage cuts/%05d.png[00000-20099] -tile 10x30 -background white
    -geometry +0+0 -units PixelsPerInch -density 150 book/1_%02d.png
    montage cuts/%05d.png[20100-40199] -tile 10x30 -background white
    -geometry +0+0 -units PixelsPerInch -density 150 book/2_%02d.png
    montage cuts/%05d.png[40200-60299] -tile 10x30 -background white
    -geometry +0+0 -units PixelsPerInch -density 150 book/3_%02d.png