Compare commits

...

4 Commits

Author SHA1 Message Date
Marcus 7b11d014af help and README 2024-01-06 16:55:10 +01:00
Marcus 13e392f9f0 supporting ANIMATION which takes a gif file as input 2024-01-06 16:50:45 +01:00
Marcus 06ff88d9c2 animation wip-2 2024-01-06 15:37:22 +01:00
Marcus 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`
- default field size are 64k lines. You can adjust it with LOLFIELDSIZE:
`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
$ ./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)
BORDERCOLOR(hex), X(int), Y(int), X_MAX(int), Y_MAX(int), H(int), W(int)
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,

View File

@ -10,11 +10,16 @@ test -z "$IPFLOOT" && IPFLOOT="130.185.104.31"
test -z "$FLOOTPORT" && FLOOTPORT="1234"
########################################################################
FNAME="$(echo $2 | sed -e 's/\..*$//' -e 's/^images\///')"
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"
HEXPPM="images/$FNAME.hexppm"
PIXLIST="/tmp/$FNAME.pixlist"
ANIFILE="/tmp/$FNAME"
SHUFMODE="$3"
FLOOTSRUNNING=0
@ -37,7 +42,20 @@ test -z "$BOUNCESTEP" && BOUNCESTEP=2
# /dev/shm/foo to store frame counter
#
# 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
@ -48,6 +66,13 @@ declare -a PIXMAP
declare -a LOL
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)
RED="\e[31m"
@ -227,6 +252,12 @@ done
convertimg() {
if [ -z "$1" ]
then
CONVERTFILE="$IMGFILE"
else
CONVERTFILE="$1"
fi
if [ -n "$RESIZE" ]
then
@ -234,7 +265,7 @@ convertimg() {
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()
{
while true
@ -299,6 +348,17 @@ flootworker()
do
echo "${LOL[$i]}"
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
xymode
echo "$OFFSET
@ -319,30 +379,52 @@ checkfile() {
loadLOL() {
# when LARGE true, then we slize the large pixlist into smaller pieces
# max 64k each one
if [ $LARGE ]
then
# when LARGE true, then we slize the large pixlist into smaller pieces
# max 64k each one
if [ $LARGE ]
then
LOL_org="$(echo "$LOL_org" | shuf)"
test -z "$LOLFIELDSIZE" && LOLFIELDSIZE=64000
# line counter
L=1
LINES="$(echo "$LOL_org" | wc -l )"
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
while [ $i -le $LOLFIELDS ]
do
LN=$(($L+$LOLFIELDSIZE+1))
message "field ${YELLOW}${i}${ENDCOLOR}, lines ${YELLOW}${L}${ENDCOLOR} - ${YELLOW}${LN}${ENDCOLOR}"
LOL[$i]="$(echo "$LOL_org" | sed -n "${L},$(($LN-1))p;${LN}q" )"
L=$LN
i=$(($i+1))
LN=$(($L+$LOLFIELDSIZE+1))
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" )"
L=$LN
i=$(($i+1))
done
elif [ $ANIMATION ]
then
else
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
for i in $(seq 1 $FLOOTFORKS)
do
if [ -z "$ALPHACOLOR" ]
@ -355,7 +437,7 @@ loadLOL() {
fi
done
fi
fi
}
@ -405,32 +487,49 @@ floot() {
;;
*)
# generate a tmp file, as i have trouble atm to figure out
# why free space get lost when i generate the pixlist directly
# in ram
if [ $USECACHE ]
if [ $ANIMATION ]
then
checkfile $PIXLIST
message "using cache from ${YELLOW}$PIXLIST${ENDCOLOR}"
LOL_org="$(< $PIXLIST)"
else
checkfile $IMGFILE
message "convertimg image file ${YELLOW}${IMGFILE}${ENDCOLOR}"
LOL_org="$(convertimg)"
#convertimg > $PIXLIST
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 ]
then
checkfile $PIXLIST
message "using cache from ${YELLOW}$PIXLIST${ENDCOLOR}"
LOL_org="$(< $PIXLIST)"
else
checkfile $IMGFILE
message "convertimg image file ${YELLOW}${IMGFILE}${ENDCOLOR}"
LOL_org="$(convertimg)"
#convertimg > $PIXLIST
fi
fi
message "prepare worker ${YELLOW}$i${ENDCOLOR} .."
#set -x
loadLOL
#set +x
message "${GREEN}DONE!${ENDCOLOR}"
message "prepare worker .."
#set -x
loadLOL
#set +x
message "${GREEN}DONE!${ENDCOLOR}"
;;
esac
message "starting $FLOOTFORKS workers"
if [ $ANIMATION ]
then
frametick &
fi
message "starting ${YELLOW}${FLOOTFORKS}${ENDCOLOR} workers"
while true
do
for i in $(seq $FLOOTFORKS)
@ -439,7 +538,7 @@ floot() {
if [ -z ${LOLPID[$i]} ] || ! ps -p ${LOLPID[$i]} > /dev/null
then
message "worker ${YELLOW}$i${ENDCOLOR} is not running, starting it"
if [ $LARGE ]
if [ $LARGE ] || [ $ANIMATION ]
then
flootworker $LOLFIELDS &
LOLPID[$i]=$!
@ -503,11 +602,22 @@ case $1 in
;;
esac
if ! command -v convert > /dev/null
for imgmgckCMD in convert identify
do
if ! command -v $imgmgckCMD > /dev/null
then
message error "imagemagick ${YELLOW}${imgmgckCMD}${ENDCOLOR} not found"
exit 1
fi
done
if [ $LARGE ] && [ $ANIMATION ]
then
message error "${YELLOW}convert${ENDCOLOR} not found"
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}"
floot
;;
@ -536,6 +646,7 @@ case $1 in
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 "RESIZE(int), ALPHACOLOR(hex), BOUNCESTEP(int), LARGE(bool), LOLFIELDSIZE(int)"
echo "ANIMATION(bool), FRAMETICKTIME(float)"
exit 1
;;