This bashscript is the heart of the lacmachine. It selects graphics according to information about possible connectors and a random value dictated by a density value and write their filepaths into text files. These lists of graphics are used in the next step to arrange the graphics to a poster illustration, where each graphic is dependent on the 4 graphics surrounding it, similar to Conway’s Game of Life.
The graphics were created manually with all being centered inside a square and having a possible connection point on each side. The script writes according to rules lists (one for each line) with filepaths which will be later on used to generate the final graphic.
There are 5 different possiblities to position the graphics inside the grid.
- at the bottom
- on the left
- on the right
- at the top
- elsewhere
The script starts bottom right. It knows it needs a file which has:
- no connector on the right
- no connector on the bottom
With this information the script generates a string which will be used as pattern to search for a matching file. The file which matches the position must have the following name:
FILENAME _ X _ 0 _ 0 _ X _.svg
while X can be a random value, 0
or 1
.
After filling the random values (e.g. _1_0_0_1_
),
it searches for file which matches the pattern e.g. *_1_0_0_1_.svg
.
Explained
The parsing of the correct filename is done for each position, treating all exceptions. Here is an example for the standard case (without exceptions for the very right, left, top).
$F1
, $F2
, $F3
and $F4
are the variables for the connection points.
F1=`echo $VARCONNECTORS | cut -c $RBNDOM` F2=$F4 # F3 IS DEFINED AT LOOPSTART F4=`echo $VARCONNECTORS | cut -c $RCNDOM`RNDMZR=`ls $TILEDIR |\ grep $F1"_"$F2"_"$F3"_"$F4"_".svg |\ rl --count=1`echo $TILEPATH/$RNDMZR >> $LS
F1=`echo $VARCONNECTORS | cut -c $RBNDOM`
$F1
is the top connector and can be random except for the very top line.
$VARCONNECTORS
is a nine-digit string consisting of 0s and 1s
from which we extract one random character with cut
.
F2=$F4
$F2
is the right connector. $F4
is the left connector.
To get no connections pointing to nothing the value for
the left has to be the same as it was previously for the right.
0 matches 0, 1 matches 1.
# F3 IS DEFINED AT LOOPSTART
$F3
is the bottom connector.
It can be defined one time at the beginning of the while
–loop because
there are no exceptions because it completly depends on previously
selected graphics (or it is 0 for the bottom line). We just read the
corresponding line from the list generated in the step before.
if [ $J -gt 1 ] then F3=`sed -n "$((LINE))p" $LSBEFORE | cut -d _ -f 2` else F3=0 fi
$J
is the vertical position. So if were not at the bottom line,
the bottom connecor of the graphic in the
current list
must match the top connector of the graphic in the same line in the
previously generated list.
If the preceeding graphics’s top connector
($F1
) is 0 the bottom connector now ($F3
) must be also 0.
F3=F1
(from the same line in the previously created list).
F4=`echo $VARCONNECTORS | cut -c $RBNDOM`
$F4
can be random except for the very left side (there it must be 0).
Now we can search for this pattern ($F1"_"$F2"_"$F3"_"$F4"_"
) inside the
graphic directory,
select from the results a random file (rl
) and write it into the
list.
RNDMZR=`ls $TILEDIR |\ grep $F1"_"$F2"_"$F3"_"$F4"_".svg |\ rl --count=1`echo $TILEPATH/$RNDMZR >> $LS
The random value
The seed for the random value (the variable $VARCONNECTORS
)
is set by following commands:
VARCONNECTORS=`sed -n '/ACCUMULATION/p' ./ioioi.sh |\ sed -n '/sed/!p' |\ cut -d "#" -f 2 |\ rl --count=1`
- Find all lines inside the file ioioi.sh which contain ACCUMULATION.
- From these lines remove all lines which contain sed (otherwise it would also get the line sed –n ‘/ACCUMULATION/p’)
- cut out the second field which are separated by the delimiter #.
Now the script has a string which looks something like 001110000. To create randomly 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 random 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 former generated random number