pixelfloot/pixelfloot_bash.sh

212 lines
4.1 KiB
Bash
Raw Normal View History

2023-12-30 10:22:50 +01:00
#!/bin/bash
IPFLOOT="151.217.15.90"
COLOR="FFFFFF"
PPMFILE="$2.ppm"
HEXPPM="$2.hexppm"
PIXLIST="$2.pixlist"
ALPHACOLOR="$3"
2023-12-30 11:37:49 +01:00
FNAME="$2"
2023-12-30 10:22:50 +01:00
declare -a PIXMAP
declare -a LOL
declare -a LOLPID
# https://gist.github.com/nberlette/e3e303a81f2c41927bf4fe90fb89d97f
function hex() {
printf "%02X%02X%02X" ${*//','/' '}
}
gen_pixmap() {
y=0
while read -r LINE
do
if [ "$y" -gt 2 ]
then
for x in $(seq 1 $x_ppm)
do
REDindex=$((x*3-2))
GREENindex=$((x*3+1-2))
BLUEindex=$((x*3+2-2))
REDvalue="$(echo $LINE| cut -d ' ' -f${REDindex})"
GREENvalue="$(echo $LINE| cut -d ' ' -f${GREENindex})"
BLUEvalue="$(echo $LINE| cut -d ' ' -f${BLUEindex})"
PIXELcolor="$(hex ${REDvalue} $GREENvalue $BLUEvalue)"
PIXMAP[$y]="${PIXMAP[$y]} $PIXELcolor"
done
echo "please wait"
echo ${PIXMAP[$y]} >> $HEXPPM
elif [ "$y" -eq 1 ]
then
x_ppm="$(echo "$LINE"|cut -d ' ' -f1)"
fi
y=$((y+1))
#~ for col in $LINE
#~ do
#~ case $count in
#~ 0) RED="$(hex $col)"
#~ ;;
#~ 1) GREEN="$(hex $col)"
#~ ;;
#~ 2) BLUE="$(hex $col)"
#~ ;;
#~ esac
#~ count=$((count+1))
#~ test $count -ge 2 && count=0
#~ done
done < "$PPMFILE"
}
gen_field() {
for i in $(seq 0 160)
do
for j in $(seq 180 330)
do
echo "PX $i $j $COLOR"
done
done
}
draw_pixmap() {
y=1
while read -r LINE
do
2023-12-30 13:27:55 +01:00
for x in $(seq 1 160)
2023-12-30 10:22:50 +01:00
do
2023-12-30 11:37:49 +01:00
if [[ "$(echo $LINE | cut -d ' ' -f$x)" != "FF00FE" ]]
then
echo "please wait"
echo "PX $((x*2)) $((y*2)) $(echo $LINE | cut -d ' ' -f$x)" >> $PIXLIST
echo "PX $((x*2+1)) $((y*2)) $(echo $LINE | cut -d ' ' -f$x)" >> $PIXLIST
echo "PX $((x*2)) $((y*2+1)) $(echo $LINE | cut -d ' ' -f$x)" >> $PIXLIST
echo "PX $((x*2+1)) $((y*2+1)) $(echo $LINE | cut -d ' ' -f$x)" >> $PIXLIST
else
2023-12-30 13:11:33 +01:00
2023-12-30 13:27:55 +01:00
if [ "$y" -lt 32 ]
2023-12-30 13:11:33 +01:00
then
RAINBOWCOLOR="$(hex 0 0 255)"
2023-12-30 13:27:55 +01:00
elif [ "$y" -lt 64 ]
2023-12-30 13:11:33 +01:00
then
RAINBOWCOLOR="$(hex 0 255 255)"
2023-12-30 13:27:55 +01:00
elif [ "$y" -lt 94 ]
2023-12-30 13:11:33 +01:00
then
RAINBOWCOLOR="$(hex 0 255 0)"
2023-12-30 13:27:55 +01:00
elif [ "$y" -lt 126 ]
2023-12-30 13:11:33 +01:00
then
RAINBOWCOLOR="$(hex 255 255 0)"
else
RAINBOWCOLOR="$(hex 255 0 0)"
fi
#~ if [ "$y" -lt 16 ]
#~ then
#~ RAINBOWCOLOR="$(hex 0 0 $(((y+1)*16)))"
#~ elif [ "$y" -lt 32 ]
#~ then
#~ RAINBOWCOLOR="$(hex 0 $(((y-16)*16)) 255)"
#~ elif [ "$y" -lt 48 ]
#~ then
#~ RAINBOWCOLOR="$(hex 0 $((y*16)) $((16-(y-32)*16)))"
#~ elif [ "$y" -lt 64 ]
#~ then
#~ RAINBOWCOLOR="$(hex $((y*16)) $((y*16)) 0)"
#~ else
#~ RAINBOWCOLOR="$(hex $((y*16)) 0 0)"
#~ fi
2023-12-30 11:37:49 +01:00
echo "please wait for rainbow"
echo "PX $((x*2)) $((y*2)) $RAINBOWCOLOR" >> $PIXLIST
echo "PX $((x*2+1)) $((y*2)) $RAINBOWCOLOR" >> $PIXLIST
echo "PX $((x*2)) $((y*2+1)) $RAINBOWCOLOR" >> $PIXLIST
echo "PX $((x*2+1)) $((y*2+1)) $RAINBOWCOLOR" >> $PIXLIST
fi
2023-12-30 10:22:50 +01:00
done
y=$((y+1))
done < "$HEXPPM"
}
sx=0
sy=0
shuf_xy() {
2023-12-30 17:10:18 +01:00
echo "OFFSET $(shuf -i 0-1760 -n 1) $(shuf -i 0-919 -n 1)"
2023-12-30 10:22:50 +01:00
#echo "OFFSET $(shuf -i 0-1760 -n 1) 919"
2023-12-30 17:10:18 +01:00
#echo "OFFSET 1200 420"
2023-12-30 10:22:50 +01:00
#echo > /dev/null
#~ echo "OFFSET $sx $sy"
#~ sx=$((sx+1))
#~ sy=$((sy+1))
#~ test $sx -gt 1760 && sx=0
#~ test $sy -gt 920 && sy=0
}
floot() {
2023-12-30 11:37:49 +01:00
#~ for i in 1 2
#~ do
2023-12-30 10:22:50 +01:00
#LOL[$i]="OFFSET 1 200"
#LOL[$i]="OFFSET $(shuf -i 0-1760 -n 1) $(shuf -i 0-920 -n 1)"
# LOL[$i]="$(shuf_xy)"
#~ LOL[$i]="$(shuf_xy)
#~ $(cat $PIXLIST | shuf)"
2023-12-30 11:37:49 +01:00
#~ if [ -z "$ALPHACOLOR" ]
#~ then
#~ LOL[$i]="$(cat $PIXLIST | shuf)"
#~ else
#~ LOL[$i]="$(grep -v $ALPHACOLOR $PIXLIST | shuf)"
#~ fi
2023-12-30 10:22:50 +01:00
2023-12-30 11:37:49 +01:00
#~ done
LOL[1]="$(cat ${FNAME}1.pixlist | shuf)"
LOL[2]="$(cat ${FNAME}2.pixlist | shuf )"
2023-12-30 14:38:37 +01:00
LOL[3]="$(cat ${FNAME}2.pixlist | shuf )"
2023-12-30 11:37:49 +01:00
#LOL[3]="$(cat $FNAME-mc.pixlist.2 | shuf)"
2023-12-30 10:22:50 +01:00
while true
do
2023-12-30 14:38:37 +01:00
for i in 1 2 3
2023-12-30 10:22:50 +01:00
do
if [ -z ${LOLPID[$i]} ] || ! ps -p ${LOLPID[$i]} > /dev/null
then
echo "$(shuf_xy)
${LOL[$i]}" > /dev/tcp/$IPFLOOT/1337 &
#echo "${LOL[$i]}" > /dev/tcp/127.0.0.1/1337 &
LOLPID[$i]=$!
fi
done
done
}
case $1 in
draw_pixmap) draw_pixmap
;;
gen_pixmap) gen_pixmap
;;
floot) floot
;;
*)
echo "lol: draw_pixmap, gen_pixmap, floot"
exit 1
;;
esac