Ticket #8: 7draw.sh

File 7draw.sh, 1.0 KB (added by Christian Illy, 11 years ago)

From https://gist.github.com/oberhamsi/10415802

Line 
1#!/bin/bash
2# requires:
3# imagemagick, bc
4
5#map = 6x6 blocks
6#one block: 512
7#image size: 1536x1536
8
9cd /home/sdtd/7draw/
10
11TELNET_PWD=volume7
12TELNET_PORT=8081
13#. /etc/7dtd.conf
14
15RADIUS=5
16LP=`echo -e "$TELNET_PWD\nlp" | nc -q 2 localhost $TELNET_PORT`
17POSLINES=`echo "$LP" | grep -oE "pos=\([^)]*\)"`
18# remove brackets
19POSLINES=`echo "$POSLINES" | tr -d ")("`
20
21#enable for debug
22#POSLINES="-221.7, 85.0, -684.6\n221.7, 85.0, 684.6"
23if [ -n "$POSLINES" ]; then
24 DATE=`date +"%Y.%m.%d"`
25 HOUR=`date +"%H"`
26 MIN=`date +"%M"`
27 HUE=`echo "(100 * (($HOUR * 60) + $MIN)) / 1440" | bc`
28 COLOR="hsb($HUE%, 100%, 100%)"
29 IMG_OUT="map_$DATE.png"
30 if [ ! -f "$IMG_OUT" ]; then
31 IMG_IN=NavezganeMap.png
32 else
33 IMG_IN="$IMG_OUT"
34 fi
35 echo -e "$POSLINES" | while IFS=", " read x _ y
36 do
37 X=`echo "768 - $x/2" | bc`
38 Y=`echo "768 - $y/2" | bc`
39 X2=`echo "$X+$RADIUS" | bc`
40 Y2=`echo "$Y+$RADIUS" | bc`
41 `convert "$IMG_IN" -fill "$COLOR" -draw "circle $X,$Y $X2,$Y2" "$IMG_OUT"`
42 IMG_IN="$IMG_OUT"
43 done
44fi