Improve and add 2012/endoh1 try scripts
The new try.sh and try.bw.sh scripts run the program on one file (passed to the script) in colour and without colour respectively. One file because one has to terminate the program. The new try.alt.bw.sh is like try.alt.sh but uses the black and white (original submitted entry) version. The scripts for the alt code allow one to set the different variables that can be redefined. The use is the same variable names as in the Makefile. For instance: TIMER=5 SLEEP=5000 GRAVITY=I VISCOSITY=4 PRESSURE=1 ./try.alt.sh TIMER=5 SLEEP=5000 GRAVITY=I VISCOSITY=4 PRESSURE=1 ./try.bw.alt.sh for the gravity 'I' and: TIMER=5 SLEEP=5000 GRAVITY=N VISCOSITY=4 PRESSURE=1 ./try.alt.sh TIMER=5 SLEEP=5000 GRAVITY=N VISCOSITY=4 PRESSURE=1 ./try.bw.alt.sh where 'N' is some number. Obviously the other values can have different values than given above. Some of these values are protected against in code (to an extent - if the user wants to set them to strings that's on them) but not all are and the scripts do not try and check for the user either. The endoh1.alt.c file was changed in that one can now define SLEEP (S in the code) to 0 like the original, should they want to see the original but with other values specified. That will make it flash much more quickly which can be a problem of course but that's up to each user.
This commit is contained in:
1 parent
d70996ef22
commit
ad703d3188
9 files changed
+269
-73
No files matched your search
+57
-13
@@ -1,34 +1,76 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.alt.sh - demonstrate IOCCC winner 2012/endoh1 alt code
|
||||
# try.alt.sh - demonstrate IOCCC winner 2012/endoh1 alt code with colour
|
||||
#
|
||||
|
||||
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
|
||||
# this way allows us to have the user specify a different compiler in an easy
|
||||
# way.
|
||||
if [[ -z "$CC" ]]; then
|
||||
CC="cc"
|
||||
fi
|
||||
[[ -z "$CC" ]] && CC="cc"
|
||||
|
||||
# We will use a timer (alarm(3) value) of 10 (the default) but we will allow the
|
||||
# user to redefine it. The code protects against negative values and values > 60
|
||||
# (arbitrary) but if the user is silly enough to specify a value that is not a
|
||||
# number that's on them.
|
||||
[[ -z "$TIMER" ]] && TIMER=10
|
||||
|
||||
# We will use a sleep value of 39000 but just like the others we will let the
|
||||
# user override it if they so wish. The code protects against values < 0 but if
|
||||
# someone chooses a value that's not a number that's on them.
|
||||
[[ -z "$SLEEP" ]] && SLEEP=39000
|
||||
|
||||
# We will let users redefine GRAVITY but only for the version that is NOT I
|
||||
# (letter I not digit 1). Just like the others we do not protect against input
|
||||
# that is not a number and in the case of GRAVITY it is even documented that
|
||||
# some non number values (I) are good to try.
|
||||
[[ -z "$GRAVITY" ]] && GRAVITY=1
|
||||
|
||||
# We will use the default 8 for VISCOSITY but we'll allow the user to redefine
|
||||
# it. We don't protect against < 0 as it doesn't seem to break the program to
|
||||
# have < 0 but if they set it to a non number value that's on them.
|
||||
[[ -z "$VISCOSITY" ]] && VISCOSITY=8
|
||||
|
||||
# We will use the default PRESSURE of 4 but like the other variables we will let
|
||||
# the user redefine it. We do not protect against any value, even non-numbers.
|
||||
# If someone wants to set it to something else that's on them.
|
||||
[[ -z "$PRESSURE" ]] && PRESSURE=4
|
||||
|
||||
# unlike other try.sh/try.alt.sh scripts this one has two compiled binaries: one
|
||||
# which sets the gravity factor to I and the other that does not.
|
||||
make clobber CC="$CC" TIMER=10 GRAVITY=I SLEEP=39000 alt >/dev/null || exit 1
|
||||
# which sets the gravity factor to I (letter I, not digit 1) and the other that
|
||||
# does not. Thus we do not compile it like the others.
|
||||
echo "$ make clobber CC=$CC TIMER=$TIMER SLEEP=$SLEEP GRAVITY=I VISCOSITY=$VISCOSITY PRESSURE=$PRESSURE alt" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue: "
|
||||
echo 1>&2
|
||||
make clobber CC="$CC" TIMER="$TIMER" SLEEP="$SLEEP" GRAVITY=I VISCOSITY="$VISCOSITY" PRESSURE="$PRESSURE" alt >/dev/null || exit 1
|
||||
# we have to move the endoh1_color.alt to endoh1_color.alt3, not alt2, because
|
||||
# we have to use make clobber which would wipe out endoh1_color.alt2.
|
||||
mv endoh1_color.alt endoh1_color.alt3
|
||||
make clobber CC="$CC" TIMER=10 SLEEP=39000 alt >/dev/null || exit 1
|
||||
read -r -n 1 -p "Press any key run run slower fluid on endoh1_color.alt.c: "
|
||||
mv endoh1_color.alt3 endoh1_color.alt2
|
||||
read -r -n 1 -p "Press any key to move endoh1_color.alt to endoh1_color.alt3: "
|
||||
echo 1>&2
|
||||
mv -v endoh1_color.alt endoh1_color.alt3
|
||||
echo 1>&2
|
||||
echo "$ make clobber CC=$CC TIMER=$TIMER SLEEP=$SLEEP GRAVITY=$GRAVITY VISCOSITY=$VISCOSITY PRESSURE=$PRESSURE alt" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue: "
|
||||
echo 1>&2
|
||||
make clobber CC="$CC" TIMER="$TIMER" SLEEP="$SLEEP" GRAVITY="$GRAVITY" VISCOSITY="$VISCOSITY" PRESSURE="$PRESSURE" alt >/dev/null || exit 1
|
||||
read -r -n 1 -p "Press any key to move endoh1_color.alt3 to endoh1_color.alt2: "
|
||||
echo 1>&2
|
||||
mv -v endoh1_color.alt3 endoh1_color.alt2
|
||||
# clear screen before continuing
|
||||
clear
|
||||
|
||||
|
||||
# now that we have both binaries we can run each one on the data files, first
|
||||
# the source file.
|
||||
read -r -n 1 -p "Press any key to run: ./endoh1_color.alt < endoh1_color.alt.c 2>/dev/null: "
|
||||
echo 1>&2
|
||||
./endoh1_color.alt < endoh1_color.alt.c 2>/dev/null
|
||||
echo 1>&2
|
||||
# reset terminal sanity
|
||||
reset
|
||||
read -r -n 1 -p "Press any key to run: ./endoh1_color.alt2 < endoh1_color.alt.c 2>/dev/null: "
|
||||
echo 1>&2
|
||||
./endoh1_color.alt2 < endoh1_color.alt.c 2>/dev/null
|
||||
clear
|
||||
# reset terminal sanity
|
||||
reset
|
||||
|
||||
# for each of the supplied text files we will run both 'versions' on them, in
|
||||
# succession, prompting the user for each text file so they know the name.
|
||||
@@ -40,8 +82,10 @@ for i in clock.txt column.txt column2.txt column3.txt corners.txt \
|
||||
# to make it more 'fluid' :-) we only prompt once per file even though the
|
||||
# second command is a different file in that the gravity factor is set to I.
|
||||
read -r -n 1 -p "Press any key to run: ./endoh1_color.alt < $i: "
|
||||
clear
|
||||
./endoh1_color.alt < "$i" 2>/dev/null
|
||||
clear
|
||||
./endoh1_color.alt2 < "$i" 2>/dev/null
|
||||
clear
|
||||
# reset terminal sanity
|
||||
reset
|
||||
done
|
||||
Reference in new issue
Block a user