Compare commits

...

4 commits

Author SHA1 Message Date
7b11d014af help and README 2024-01-06 16:55:10 +01:00
13e392f9f0 supporting ANIMATION which takes a gif file as input 2024-01-06 16:50:45 +01:00
06ff88d9c2 animation wip-2 2024-01-06 15:37:22 +01:00
6641771171 animation wip 2024-01-06 14:17:40 +01:00
2 changed files with 153 additions and 39 deletions

View file

@ -26,6 +26,8 @@ pixelfloot was built during the 37c3. in its actual state, its just a mess. I ho
- for drawing big areas, like 1280x720, use LARGE mode: `LARGE=true ./pixelfloot.sh floot images/xphg.jpg` - for drawing big areas, like 1280x720, use LARGE mode: `LARGE=true ./pixelfloot.sh floot images/xphg.jpg`
- default field size are 64k lines. You can adjust it with LOLFIELDSIZE: - default field size are 64k lines. You can adjust it with LOLFIELDSIZE:
`LOLFIELDSIZE=16000 LARGE=true ./pixelfloot.sh floot images/xphg.jpg` `LOLFIELDSIZE=16000 LARGE=true ./pixelfloot.sh floot images/xphg.jpg`
- drawing an gif file with proper animation: `LARGE=true ./pixelfloot.sh floot images/dancing_banana.gif`
- Adjust the speed with FRAMETICKTIME in seconds: `FRAMETICKTIME=0.03 LARGE=true ./pixelfloot.sh floot images/shaking_cat.gif`
```shell ```shell
$ ./pixelfloot.sh help $ ./pixelfloot.sh help
@ -53,6 +55,7 @@ IPFLOOT(string), FLOOTPORT(int), USECACHE(bool), FLOOTFORKS(int)
SIZE(int), TEXT(string), FONTSIZE(int), BGCOLOR(hex), COLOR(hex) SIZE(int), TEXT(string), FONTSIZE(int), BGCOLOR(hex), COLOR(hex)
BORDERCOLOR(hex), X(int), Y(int), X_MAX(int), Y_MAX(int), H(int), W(int) BORDERCOLOR(hex), X(int), Y(int), X_MAX(int), Y_MAX(int), H(int), W(int)
RESIZE(int), ALPHACOLOR(hex), BOUNCESTEP(int), LARGE(bool) RESIZE(int), ALPHACOLOR(hex), BOUNCESTEP(int), LARGE(bool)
ANIMATION(bool), FRAMETICKTIME(float)
``` ```
Running on my Ryzen 4700G with [wellenbrecher](https://github.com/bits0rcerer/wellenbrecher) 1280x720 and three workers, Running on my Ryzen 4700G with [wellenbrecher](https://github.com/bits0rcerer/wellenbrecher) 1280x720 and three workers,

View file

@ -10,11 +10,16 @@ test -z "$IPFLOOT" && IPFLOOT="130.185.104.31"
test -z "$FLOOTPORT" && FLOOTPORT="1234" test -z "$FLOOTPORT" && FLOOTPORT="1234"
######################################################################## ########################################################################
FNAME="$(echo $2 | sed -e 's/\..*$//' -e 's/^images\///')"
IMGFILE="$2" IMGFILE="$2"
# remove file extension
FNAME="${2%.*}"
# remove everything before the slash, so we get the filename without
# path and extension
FNAME="${FNAME##*/}"
PPMFILE="$FNAME.ppm" PPMFILE="$FNAME.ppm"
HEXPPM="images/$FNAME.hexppm" HEXPPM="images/$FNAME.hexppm"
PIXLIST="/tmp/$FNAME.pixlist" PIXLIST="/tmp/$FNAME.pixlist"
ANIFILE="/tmp/$FNAME"
SHUFMODE="$3" SHUFMODE="$3"
FLOOTSRUNNING=0 FLOOTSRUNNING=0
@ -37,7 +42,20 @@ test -z "$BOUNCESTEP" && BOUNCESTEP=2
# /dev/shm/foo to store frame counter # /dev/shm/foo to store frame counter
# #
# GifFileFormat - gif, jpg, png || detect which fileformat IMGFILE is # GifFileFormat - gif, jpg, png || detect which fileformat IMGFILE is
test -z "$ANIMATION" && ANIMATION="false" #test -z "$ANIMATION" && ANIMATION="false"
#
# loadLOL loads every single frame into an array field WHEN ANIMATION is true
# loadLOL sets No of frames in LOLFIELDS
#
# flootworker looks in while loop which value in /dev/shm/frametick is.
# /dev/shm/frametick contains which frame from LOL to draw.
# function frametick() gets started in background when ANIMATION is true
# and gets started before the flootworker get started
# frametick writes the no of frame to draw into /dev/shm/frametick
# to not draw too fast, there is a sleep in frametick which waits for
# FRAMETICKTIME seconds. Values are float, down to lowest value 0.001
# Only one of ANIMATION or LARGE can be true, not both.
FRAMETOPICK_SHM="/dev/shm/pxlflt-frametopick"
## END ANIMATION ## END ANIMATION
@ -48,6 +66,13 @@ declare -a PIXMAP
declare -a LOL declare -a LOL
declare -a LOLPID declare -a LOLPID
## TODOS
#
# - Put OFFSET into /dev/shm/ so each worker do not have to count OFFSET
# for itself and we prevent worker from drifting apart when drawing.
# - get dimensions of pic with "identify" (imagemagick part)
# - get dimensions of the pixelflut board
# colors for colored output 8) # colors for colored output 8)
RED="\e[31m" RED="\e[31m"
@ -227,6 +252,12 @@ done
convertimg() { convertimg() {
if [ -z "$1" ]
then
CONVERTFILE="$IMGFILE"
else
CONVERTFILE="$1"
fi
if [ -n "$RESIZE" ] if [ -n "$RESIZE" ]
then then
@ -234,7 +265,7 @@ convertimg() {
fi fi
convert $IMGFILE $BORDER $RESIZE txt: | tail -n +2 | awk '{print $1 $3}' | sed -e 's/\,/ /' -e 's/\:/ /' -e 's/\#//' -e 's/^/PX /' convert $CONVERTFILE $BORDER $RESIZE txt: | tail -n +2 | awk '{print $1 $3}' | sed -e 's/\,/ /' -e 's/\:/ /' -e 's/\#//' -e 's/^/PX /'
} }
@ -287,6 +318,24 @@ xymode() {
} }
frametick() {
test -z "$FRAMETICKTIME" && FRAMETICKTIME=0.1
#LOLFIELDS=12
i=0
while true
do
echo "$i" > $FRAMETOPICK_SHM
if [ "$i" -gt $LOLFIELDS ]
then
i=0
else
i=$(($i+1))
fi
sleep $FRAMETICKTIME
done
}
flootworker() flootworker()
{ {
while true while true
@ -299,6 +348,17 @@ flootworker()
do do
echo "${LOL[$i]}" echo "${LOL[$i]}"
done done
elif [ $ANIMATION ]
then
xymode
echo "$OFFSET"
echo "${LOL[$(<${FRAMETOPICK_SHM})]}"
#~ i=0
#~ while [ $i -le $1 ]
#~ do
#~ echo "${LOL[$i]}"
#~ i=$(($i+1))
#~ done
else else
xymode xymode
echo "$OFFSET echo "$OFFSET
@ -329,19 +389,41 @@ loadLOL() {
L=1 L=1
LINES="$(echo "$LOL_org" | wc -l )" LINES="$(echo "$LOL_org" | wc -l )"
LOLFIELDS="$(( ( $LINES / $LOLFIELDSIZE ) ))" LOLFIELDS="$(( ( $LINES / $LOLFIELDSIZE ) ))"
message "LARGE mode: slicing ${YELLOW}${IMGFILE}${ENDCOLOR} - ${YELLOW}${LINES}${ENDCOLOR} into ${YELLOW}${LOLFIELDS}${ENDCOLOR} fields" message "LARGE mode: slicing ${YELLOW}${IMGFILE}${ENDCOLOR} - ${YELLOW}${LINES}${ENDCOLOR} into ${YELLOW}$((${LOLFIELDS}+1))${ENDCOLOR} fields"
i=0 i=0
while [ $i -le $LOLFIELDS ] while [ $i -le $LOLFIELDS ]
do do
LN=$(($L+$LOLFIELDSIZE+1)) LN=$(($L+$LOLFIELDSIZE+1))
message "field ${YELLOW}${i}${ENDCOLOR}, lines ${YELLOW}${L}${ENDCOLOR} - ${YELLOW}${LN}${ENDCOLOR}" message "field ${YELLOW}${i}/${LOLFIELDS}${ENDCOLOR}, lines ${YELLOW}${L}${ENDCOLOR} - ${YELLOW}${LN}${ENDCOLOR}"
LOL[$i]="$(echo "$LOL_org" | sed -n "${L},$(($LN-1))p;${LN}q" )" LOL[$i]="$(echo "$LOL_org" | sed -n "${L},$(($LN-1))p;${LN}q" )"
L=$LN L=$LN
i=$(($i+1)) i=$(($i+1))
done done
elif [ $ANIMATION ]
then
i=0
while [ $i -lt $LOLFIELDS ]
do
if [ -z "$ALPHACOLOR" ]
then
message "load and shuffle pixels for frame ${YELLOW}$((${i}+1))/${LOLFIELDS}${ENDCOLOR}"
LOL[$i]="$(convertimg ${ANIFILE}-${i}.png | shuf)"
else
message "load and shuffle pixels for frame ${YELLOW}$((${i}+1))/${LOLFIELDS}${ENDCOLOR}, remove aplha color ${YELLOW}${ALPHACOLOR}${ENDCOLOR}"
LOL[$i]="$(convertimg ${ANIFILE}-${i}.png | grep -v $ALPHACOLOR | shuf)"
fi
#echo "${LOL[$i]}" | head
i=$(($i+1))
done
# ani
#~ echo ani ani
#~ exit 1
else else
for i in $(seq 1 $FLOOTFORKS) for i in $(seq 1 $FLOOTFORKS)
do do
@ -405,9 +487,20 @@ floot() {
;; ;;
*) *)
# generate a tmp file, as i have trouble atm to figure out if [ $ANIMATION ]
# why free space get lost when i generate the pixlist directly then
# in ram checkfile $IMGFILE
message "ANIMATION mode, checking if ${YELLOW}${IMGFILE}${ENDCOLOR} is an GIF"
if [ "$(file $IMGFILE |awk '{print $2}')" == "GIF" ]
then
LOLFIELDS="$(identify $IMGFILE | wc -l )"
message "splitting ${YELLOW}${IMGFILE}${ENDCOLOR} up into ${YELLOW}${LOLFIELDS}${ENDCOLOR} frame images"
convert -coalesce $IMGFILE ${ANIFILE}.png || error
else
message error "Other filetypes then ${YELLOW}GIF${ENDCOLOR} are not supported at the moment for ${YELLOW}ANIMATION${ENDCOLOR}"
exit 1
fi
else
if [ $USECACHE ] if [ $USECACHE ]
then then
checkfile $PIXLIST checkfile $PIXLIST
@ -419,8 +512,8 @@ floot() {
LOL_org="$(convertimg)" LOL_org="$(convertimg)"
#convertimg > $PIXLIST #convertimg > $PIXLIST
fi fi
fi
message "prepare worker ${YELLOW}$i${ENDCOLOR} .." message "prepare worker .."
#set -x #set -x
loadLOL loadLOL
#set +x #set +x
@ -428,8 +521,14 @@ floot() {
;; ;;
esac esac
message "starting $FLOOTFORKS workers"
if [ $ANIMATION ]
then
frametick &
fi
message "starting ${YELLOW}${FLOOTFORKS}${ENDCOLOR} workers"
while true while true
do do
@ -439,7 +538,7 @@ floot() {
if [ -z ${LOLPID[$i]} ] || ! ps -p ${LOLPID[$i]} > /dev/null if [ -z ${LOLPID[$i]} ] || ! ps -p ${LOLPID[$i]} > /dev/null
then then
message "worker ${YELLOW}$i${ENDCOLOR} is not running, starting it" message "worker ${YELLOW}$i${ENDCOLOR} is not running, starting it"
if [ $LARGE ] if [ $LARGE ] || [ $ANIMATION ]
then then
flootworker $LOLFIELDS & flootworker $LOLFIELDS &
LOLPID[$i]=$! LOLPID[$i]=$!
@ -503,11 +602,22 @@ case $1 in
;; ;;
esac esac
if ! command -v convert > /dev/null
for imgmgckCMD in convert identify
do
if ! command -v $imgmgckCMD > /dev/null
then then
message error "${YELLOW}convert${ENDCOLOR} not found" message error "imagemagick ${YELLOW}${imgmgckCMD}${ENDCOLOR} not found"
exit 1 exit 1
fi fi
done
if [ $LARGE ] && [ $ANIMATION ]
then
message error "${YELLOW}LARGE${ENDCOLOR} and ${YELLOW}ANIMATION${ENDCOLOR} cannot be used at the same time. Please use only one of them."
exit 1
fi
message "all requirements satisfied ${GREEN}:)${ENDCOLOR}" message "all requirements satisfied ${GREEN}:)${ENDCOLOR}"
floot floot
;; ;;
@ -536,6 +646,7 @@ case $1 in
echo "SIZE(int), TEXT(string), FONTSIZE(int), BGCOLOR(hex), COLOR(hex)" echo "SIZE(int), TEXT(string), FONTSIZE(int), BGCOLOR(hex), COLOR(hex)"
echo "BORDERCOLOR(hex), X(int), Y(int), X_MAX(int), Y_MAX(int), H(int), W(int)" echo "BORDERCOLOR(hex), X(int), Y(int), X_MAX(int), Y_MAX(int), H(int), W(int)"
echo "RESIZE(int), ALPHACOLOR(hex), BOUNCESTEP(int), LARGE(bool), LOLFIELDSIZE(int)" echo "RESIZE(int), ALPHACOLOR(hex), BOUNCESTEP(int), LARGE(bool), LOLFIELDSIZE(int)"
echo "ANIMATION(bool), FRAMETICKTIME(float)"
exit 1 exit 1
;; ;;