Rearrange Github pages-related Makefile targets
[pipeglade.git] / clock.sh
blob62b8ebe0152d0eed9b5616dc1f80c345d4a1fc04
1 #!/usr/bin/env bash
3 IMG=$1 # optional image file; exit when written
6 HRLN=100
7 MNLN=195
8 SCLN=195
9 R=215
10 ## drawing a clock face
11 echo "drawingarea1:translate 10000 220 220"
12 echo "drawingarea1:set_line_cap 10000 round"
13 echo "drawingarea1:set_source_rgba 10000 black"
14 echo "drawingarea1:arc 10000 0 0 $R 0 360"
15 echo "drawingarea1:fill 10000"
16 # date
17 echo "drawingarea1:set_font_face 10000 normal bold"
18 echo "drawingarea1:set_font_size 10000 25"
19 echo "drawingarea1:set_source_rgba 10000 white"
20 echo "drawingarea1:move_to 10000 0 30"
21 echo "drawingarea1:rel_move_for 10010 n Today"
22 echo "drawingarea1:show_text 10020 Today"
23 # hour hand
24 echo "drawingarea1:set_source_rgba 10000 rgba(255,255,0,.8)"
25 echo "drawingarea1:set_dash 10000"
26 echo "drawingarea1:set_line_width 10000 30"
27 echo "drawingarea1:move_to 10000 0 0"
28 echo "drawingarea1:arc 10030 0 0 $HRLN -90 -90"
29 echo "drawingarea1:stroke 10000"
30 # minute hand
31 echo "drawingarea1:set_source_rgba 10000 rgba(0,255,0,.7)"
32 echo "drawingarea1:set_dash 10000"
33 echo "drawingarea1:set_line_width 10000 25"
34 echo "drawingarea1:move_to 10000 0 0"
35 echo "drawingarea1:arc 10040 0 0 $MNLN -90 -90"
36 echo "drawingarea1:stroke 10000"
37 # second hand
38 echo "drawingarea1:set_source_rgba 10000 cyan"
39 echo "drawingarea1:set_dash 10000 4 4"
40 echo "drawingarea1:set_line_width 10000 2"
41 echo "drawingarea1:move_to 10000 0 0"
42 echo "drawingarea1:arc 10050 0 0 $SCLN -90 -90"
43 echo "drawingarea1:stroke 10000"
44 ## now turning the hands by replacing some of the commands above
45 HR0=0
46 MN0=0
47 SC0=0
48 while true; do
49 D=`date +%F`
50 HR=$(((`date +"%s"`/1200%72*10)+270+720))
51 MN=$(((`date +"%s"`/20%180*2)+270+360))
52 SC=$((((`date +"%s"`%60)*6)+270))
53 # date and hour hand
54 if [[ HR -ne HR0 ]]; then
55 echo "drawingarea1:rel_move_for =10010 n $D"
56 echo "drawingarea1:show_text =10020 $D"
57 echo "drawingarea1:arc =10030 0 0 $HRLN $HR $HR"
58 HR0=$H
60 # minute hand
61 if [[ MN -ne MN0 ]]; then
62 echo "drawingarea1:arc =10040 0 0 $MNLN $MN $MN"
63 MN0=$MN
65 # second hand
66 echo "drawingarea1:arc =10050 0 0 $SCLN $SC $SC"
67 SC0=$SC
68 if [ -z "$IMG" ]; then # running clock
69 sleep 1
70 else # write image file and exit
71 echo "main:snapshot $IMG"
72 echo "_:main_quit"
74 done
75 ) | ./pipeglade -u clock.ui