Here's a little script that lets Ants (well, ONE Ant) crawl over the display of the Kindle Touch.
usage: ants [-c]
- without parameter, the Ant will start crawling right over the displayed document or picture (interesting effect to let it run over a title-page of a book)
- with parameter "-c", the screen is cleared before the Ant starts its work. In this case after about 12000 iterations (displayed in the top left corner), the Ant will build a "street" as any self-respecting ant will do.
- the program will stop the framework while it runs and SHOULD reactivate the framework when it is killed or ends. (However, once or twice it didn't, so best to not try this without shell-access)
- the program can be stopped with tapping the touchscreen or the home-button, with the only disadvantage being that the tap WILL be interpreted by the framework
- when the Ant reaches one of the borders, it stops
- when the Ant runs longer than the normal screensaver time, you will need to press the power-button, because the Kindle falls asleep immediately after end of the program.
PHP Code:
#!/bin/sh
#===========================
# cleanup - delete tmp files
#---------------------------
trap 'cleanup ; exit' SIGINT SIGTERM
cleanup() {
killall -cont cvm Xorg 2>/dev/null # resume framework
killall waitforkey
eips -v 2 2 "done"
}
#===========================
# initvar - init global vars
#---------------------------
initvar() {
[ "$1" = "-c" ] && eips -c
set $(eips -i|grep xres) ; XM=$2 YM=$4 LL=$6 #XMax, YMax, LineLength
AX=$((XM/2)) AY=$((YM/2)) #Ant starts in the middle of the screen
AD=0 #Ant Direction: 0=up 1=right 2=down 3=left
WK=$(mktemp "/tmp/WK.XXXXXX") # file to watch for exit
waitforkey > $WK &
DN=/dev/null DF=/dev/fb0
}
#===================================
# usage: setpix x y color; color should be in hex: e.g. 66 AA etc.
#-----------------------------------
setpix() {
local x=$1 y=$2 c=$3
echo -ne "\x$c" | dd of=$DF bs=1 count=1 seek=$((y*LL+x)) 2>$DN
}
#===================================
# usage: getpix x y; return: pixel value in hex on stdout as AA 66 ...
#-----------------------------------
getpix() {
local x=$1 y=$2
hexdump -v -s $((y*LL+x)) -n 1 -e '/1 "%02X"' $DF
}
#===================================
# loop to let the ant crawl
#-----------------------------------
loop() {
i=0
while [ ! -s $WK ] ; do # loop until file $WK is not empty
i=$((i+1))
p=$(getpix $AX $AY)
case "$p" in
"00"|"11"|"22"|"33"|"44"|"55"|"66"|"77")
setpix $AX $AY FF
AD=$((AD+1)); [ $AD -gt 3 ] && AD=0 ;;
*)
setpix $AX $AY 00
AD=$((AD-1)); [ $AD -lt 0 ] && AD=3 ;;
esac
case "$AD" in
"0") AY=$((AY-1)) ; [ $AY -lt 0 ] && exit ;;
"1") AX=$((AX+1)) ; [ $AX -gt $XM ] && exit ;;
"2") AY=$((AY+1)) ; [ $AY -gt $YM ] && exit ;;
*) AX=$((AX-1)) ; [ $AX -lt 0 ] && exit ;;
esac
[ $((i%100)) -eq 0 ] && (eips -d l=0,w=110,h=60; eips -v 2 1 "$i")
[ $((i%100)) ] && eips ''
done
rm $WK
}
killall -stop Xorg cvm 2>/dev/null # pause framework
initvar $1
loop
cleanup
killall -cont cvm Xorg 2>/dev/null # resume framework