View Single Post
Old 05-10-2012, 06:41 PM   #71
Dweia
Junior Member
Dweia plays well with othersDweia plays well with othersDweia plays well with othersDweia plays well with othersDweia plays well with othersDweia plays well with othersDweia plays well with othersDweia plays well with othersDweia plays well with othersDweia plays well with othersDweia plays well with others
 
Posts: 7
Karma: 2614
Join Date: May 2012
Device: Kindle Touch
Ants in the Kindle Touch!

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=$#XMax, YMax, LineLength
  
AX=$((XM/2)) AY=$((YM/2)) #Ant starts in the middle of the screen
  
AD=#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$cdd 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 
--$((y*LL+x)) -n 1 -'/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 
"$pin
      
"00"|"11"|"22"|"33"|"44"|"55"|"66"|"77")
        
setpix $AX $AY FF
        AD
=$((AD+1)); [ $AD -gt 3 ] && AD=;; 
      *)
        
setpix $AX $AY 00
        AD
=$((AD-1)); [ $AD -lt 0 ] && AD=;; 
    
esac
    
case "$ADin
      
"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=60eips -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 
Dweia is offline   Reply With Quote