This bash­script is the heart of the lac­ma­chine. It selects graph­ics accord­ing to infor­ma­tion about pos­si­ble con­nec­tors and a ran­dom value dic­tated by a den­sity value and write their filepaths into text files. These lists of graph­ics are used in the next step to arrange the graph­ics to a poster illus­tra­tion, where each graphic is depen­dent on the 4 graph­ics sur­round­ing it, sim­i­lar to Conway’s Game of Life.

The graph­ics were cre­ated man­u­ally with all being cen­tered inside a square and hav­ing a pos­si­ble con­nec­tion point on each side. The script writes accord­ing to rules lists (one for each line) with filepaths which will be later on used to gen­er­ate the final graphic.

There are 5 dif­fer­ent pos­si­b­li­ties to posi­tion the graph­ics inside the grid.

  1. at the bottom
  2. on the left
  3. on the right
  4. at the top
  5. else­where

The script starts bot­tom right. It knows it needs a file which has:

  1. no con­nec­tor on the right
  2. no con­nec­tor on the bottom

With this infor­ma­tion the script gen­er­ates a string which will be used as pat­tern to search for a match­ing file. The file which matches the posi­tion must have the fol­low­ing name:

FILENAME _ X _ 0 _ 0 _ X _.svg

while X can be a ran­dom value, 0 or 1. After fill­ing the ran­dom val­ues (e.g. _1_0_0_1_), it searches for file which matches the pat­tern e.g. *_1_0_0_1_.svg.


The pars­ing of the cor­rect file­name is done for each posi­tion, treat­ing all excep­tions. Here is an exam­ple for the stan­dard case (with­out excep­tions for the very right, left, top).

$F1, $F2, $F3 and $F4 are the vari­ables for the con­nec­tion points.

F1=`echo $VARCONNECTORS | cut -c $RBNDOM`
F4=`echo $VARCONNECTORS | cut -c $RCNDOM`
RNDMZR=`ls $TILEDIR |\ grep $F1"_"$F2"_"$F3"_"$F4"_".svg |\ rl --count=1`

F1=`echo $VARCONNECTORS | cut -c $RBNDOM`

$F1 is the top con­nec­tor and can be ran­dom except for the very top line. $VARCONNECTORS is a nine-digit string con­sist­ing of 0s and 1s from which we extract one ran­dom char­ac­ter with cut.


$F2 is the right con­nec­tor. $F4 is the left con­nec­tor. To get no con­nec­tions point­ing to noth­ing the value for the left has to be the same as it was pre­vi­ously for the right. 0 matches 0, 1 matches 1.


$F3 is the bot­tom con­nec­tor. It can be defined one time at the begin­ning of the while–loop because there are no excep­tions because it com­pletly depends on pre­vi­ously selected graph­ics (or it is 0 for the bot­tom line). We just read the cor­re­spond­ing line from the list gen­er­ated in the step before.

if [ $J -gt 1 ]
    F3=`sed -n "$((LINE))p" $LSBEFORE  | cut -d _ -f 2`

$J is the ver­ti­cal posi­tion. So if were not at the bot­tom line, the bot­tom con­necor of the graphic in the cur­rent list must match the top con­nec­tor of the graphic in the same line in the pre­vi­ously gen­er­ated list. If the pre­ceed­ing graphics’s top con­nec­tor ($F1) is 0 the bot­tom con­nec­tor now ($F3) must be also 0.
F3=F1 (from the same line in the pre­vi­ously cre­ated list).

F4=`echo $VARCONNECTORS | cut -c $RBNDOM`

$F4 can be ran­dom except for the very left side (there it must be 0).

Now we can search for this pat­tern ($F1"_"$F2"_"$F3"_"$F4"_") inside the graphic direc­tory, select from the results a ran­dom file (rl) and write it into the list.

        grep $F1"_"$F2"_"$F3"_"$F4"_".svg |\
        rl --count=1`

The ran­dom value

The seed for the ran­dom value (the vari­able $VARCONNECTORS) is set by fol­low­ing commands:

               sed -n '/sed/!p' |\
               cut -d "#" -f 2 |\
               rl --count=1`
  • Find all lines inside the file which con­tain ACCUMULATION.
  • From these lines remove all lines which con­tain sed (oth­er­wise it would also get the line sed –n ‘/ACCUMULATION/p’)
  • cut out the sec­ond field which are sep­a­rated by the delim­iter #.

Now the script has a string which looks some­thing like 001110000. To cre­ate ran­domly 0 or 1 it does the following

RBNDOM=`echo $RANDOM | cut -c 1`
X=`echo $VARCONNECTORS | cut -c $RBNDOM`
  • it echoes the bash-built-in ran­dom value $RANDOM and selects the first digit, this way it gets a value between 1 and 9
  • it echoes the string 001110000 and selects the digit defined by the for­mer gen­er­ated ran­dom number