Compare commits
4 commits
f5ec4fe401
...
7b11d014af
Author | SHA1 | Date | |
---|---|---|---|
7b11d014af | |||
13e392f9f0 | |||
06ff88d9c2 | |||
6641771171 |
2 changed files with 153 additions and 39 deletions
|
@ -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,
|
||||||
|
|
189
pixelfloot.sh
189
pixelfloot.sh
|
@ -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
|
||||||
|
@ -319,30 +379,52 @@ checkfile() {
|
||||||
|
|
||||||
loadLOL() {
|
loadLOL() {
|
||||||
|
|
||||||
# when LARGE true, then we slize the large pixlist into smaller pieces
|
# when LARGE true, then we slize the large pixlist into smaller pieces
|
||||||
# max 64k each one
|
# max 64k each one
|
||||||
if [ $LARGE ]
|
if [ $LARGE ]
|
||||||
then
|
then
|
||||||
LOL_org="$(echo "$LOL_org" | shuf)"
|
LOL_org="$(echo "$LOL_org" | shuf)"
|
||||||
test -z "$LOLFIELDSIZE" && LOLFIELDSIZE=64000
|
test -z "$LOLFIELDSIZE" && LOLFIELDSIZE=64000
|
||||||
# line counter
|
# line counter
|
||||||
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
|
||||||
|
|
||||||
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)
|
for i in $(seq 1 $FLOOTFORKS)
|
||||||
do
|
do
|
||||||
if [ -z "$ALPHACOLOR" ]
|
if [ -z "$ALPHACOLOR" ]
|
||||||
|
@ -355,7 +437,7 @@ loadLOL() {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,32 +487,49 @@ 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
|
|
||||||
# in ram
|
|
||||||
if [ $USECACHE ]
|
|
||||||
then
|
then
|
||||||
checkfile $PIXLIST
|
checkfile $IMGFILE
|
||||||
message "using cache from ${YELLOW}$PIXLIST${ENDCOLOR}"
|
message "ANIMATION mode, checking if ${YELLOW}${IMGFILE}${ENDCOLOR} is an GIF"
|
||||||
LOL_org="$(< $PIXLIST)"
|
if [ "$(file $IMGFILE |awk '{print $2}')" == "GIF" ]
|
||||||
else
|
then
|
||||||
checkfile $IMGFILE
|
LOLFIELDS="$(identify $IMGFILE | wc -l )"
|
||||||
message "convertimg image file ${YELLOW}${IMGFILE}${ENDCOLOR}"
|
message "splitting ${YELLOW}${IMGFILE}${ENDCOLOR} up into ${YELLOW}${LOLFIELDS}${ENDCOLOR} frame images"
|
||||||
LOL_org="$(convertimg)"
|
convert -coalesce $IMGFILE ${ANIFILE}.png || error
|
||||||
#convertimg > $PIXLIST
|
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
|
fi
|
||||||
|
message "prepare worker .."
|
||||||
message "prepare worker ${YELLOW}$i${ENDCOLOR} .."
|
#set -x
|
||||||
#set -x
|
loadLOL
|
||||||
loadLOL
|
#set +x
|
||||||
#set +x
|
message "${GREEN}DONE!${ENDCOLOR}"
|
||||||
message "${GREEN}DONE!${ENDCOLOR}"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
message "starting $FLOOTFORKS workers"
|
|
||||||
|
|
||||||
|
if [ $ANIMATION ]
|
||||||
|
then
|
||||||
|
frametick &
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
message "starting ${YELLOW}${FLOOTFORKS}${ENDCOLOR} workers"
|
||||||
|
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
for i in $(seq $FLOOTFORKS)
|
for i in $(seq $FLOOTFORKS)
|
||||||
|
@ -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
|
||||||
|
message error "imagemagick ${YELLOW}${imgmgckCMD}${ENDCOLOR} not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $LARGE ] && [ $ANIMATION ]
|
||||||
then
|
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
|
exit 1
|
||||||
fi
|
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
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue