[download]

local/bin/lilvice

   1 #!/bin/bash
   2 
   3 f=~/.cache/${0##*/}
   4 b=~/.theme/background
   5 r=$(xrandr | awk '/\*/ { print $1 }')
   6 
   7 [[ $1 == -r && $b -ot   $f.png ]] &&
   8 hsetroot -fill $b -fill $f.png && exit
   9 
  10 read x y w h < <(
  11     [[ $1 == -r ]] && cat $f ||
  12     slop -f '%x %y %w %h'
  13 )
  14 
  15 [[ $x ]] || exit
  16 echo "$x $y $w $h" > $f
  17 
  18 cat > $f.svg <<SVG # {{{
  19 <svg width="95.06mm" height="216.6mm" viewBox="0 0 336.8 738.7" xmlns="http://www.w3.org/2000/svg">
  20   <path d="m336.6 704.5a168.4 34.78 0 0 1 -168.4 34.5 168.4 34.78 0 0 1 -168.39-34.5 168.4 34.78 0 0 1 168.39-35 168.4 34.78 0 0 1 168.4 35z" fill-opacity=".2" stroke-linecap="round" stroke-width="2" transform="translate(0, 10)"/>
  21   <path d="m256.1 529.3c0 78.5-31.4 94.1-99.9 94.1-68.53 0-74.28-19.3-74.28-97.8 0-78.4 14.12-103 82.68-103 68.5 0 91.5 28.3 91.5 106.7z" fill="blue" stroke-linecap="round" stroke-linejoin="round" stroke-width="5"/>
  22   <path d="m100.7 474.4c-14.07-18.3-37.61-27.7-74.74-27.2 24.58-20.4 52.82-34 95.74-20.9z" fill="blue" fill-rule="evenodd"/>
  23   <path d="m246.1 477c8.9-19.9 28.3-32.9 62.3-40.3-26.7-13.6-54.9-20.4-91.5.6z" fill="blue" fill-rule="evenodd"/>
  24   <path d="m165.3 609.5c20.4-28.7 44.9-86.2 72.5-139.5 10.8-25.2 34.1-43.7 34.1-43.7l-34.7-6-52.1 107.2-27 82.6z" fill="#000" fill-opacity="0.4" fill-rule="evenodd" stroke-width=".9999"/>
  25   <path d="m159.6 614.5c-8.4-.8-37-107.5-69.76-154.1l-28.16-34.7 7.19-4.2 62.33 76z" fill="#000" fill-opacity="0.4" fill-rule="evenodd" stroke-width=".9999"/>
  26   <path d="m43.74 403.8c84.76-37.7 175.16-16.8 249.46 2.1-79 42.9-87.9 146.4-133.4 209.7-38.7-74.3-17.7-116.1-116.06-211.8z" fill="magenta" fill-rule="evenodd" stroke-width=".92"/>
  27   <path d="m171.4 435.7c-91.57-13.1-67-109.8-62.8-192.5 5.7-110.9 39.2-172.57 113-160.02 64.8 10.46 32.4 77.92 15.7 187.72-16.8 109.9 9.9 175.2-65.9 164.8z" fill="#e6c8aa" stroke-linecap="round" stroke-linejoin="round" stroke-width="5"/>
  28   <circle cx="117.5" cy="183.1" r="4.239" stroke-linecap="round" stroke-linejoin="round" stroke-width="5"/>
  29   <path d="m108.1 168.4c9.9-2.6 18.3 3.2 25.6 14.2" fill="none" stroke="#000" stroke-width="6.1714"/>
  30   <circle cx="-169.8" cy="188.3" r="4.239" stroke-linecap="round" stroke-linejoin="round" stroke-width="5" transform="scale(-1 1)"/>
  31   <path d="m179.7 173.7-26.1 14.1" fill="none" stroke="#000" stroke-width="6.1714"/>
  32   <g transform="matrix(5.014 0 0 5.014 -2492 -2615)">
  33     <path d="m532.1 567.7c0 2.3-2.6 4.3-8.3 4.3-5.8 0-5-2-5-4.3 0-2.4-.8-4.2 5-4.2 5.7 0 8.3 1.8 8.3 4.2z" fill="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="5"/>
  34     <path d="m472.7 206.4c-.1 0-.2 0-.3 0v3.3h-2.2l-.1-3.1c-.3 0-.7.1-.9.2v2.9h-1.2v.6.3h1.2v3.4c.3.1.6.2 1 .3v-3.6h2.2v3.8h.3.7v-3.8h2.8v3.5c.4-.1.7-.2 1-.3v-3.2l3.5.1c0-.2 0-.3 0-.5s0-.3 0-.5h-3.5l-.1-2.9c-.3-.1-.6-.2-.9-.3v3.2l-2.9-.1v-3.3c-.2 0-.3 0-.6 0z" fill-rule="evenodd" transform="matrix(1.043 0 0 1.043 30.66 348.3)"/>
  35   </g>
  36   <path d="m139.6 132.2s11.4 20.9 49.1 25.7c27.5 1.8 50.9-16.7 50.9-16.7l-9 15.5s-24.5 34.7-26.3 57.5c0 0-16.8 92.8-12.6 119.8 0 0 7.1 10.2 19.7 9.6 21.6-3 18.6-13.8 18.6-13.8s.6-44.3 0-49.1 8.4-86.8 8.4-86.8l25.7-44.4 7.2-32.3-91.6-20.37-57.5-3.59 6 35.96z" fill="#ddb38a" fill-rule="evenodd" stroke-width=".9999"/>
  37   <path d="m129.5 137.6c-15.7-37.2-40.26-72.2-24.6-116.65 34.6 6.8 28.8 20.39 46.6 28.24 41.8 16.73 71.6 27.19 142.8 66.41-1.1 20.4-4.7 38.2-27.8 42.9-32.9 75.3-24 119.2-37.6 171.5-7.9 6.3-17.3 8.9-33.5-4.1 3.7-46.1 2.1-131.8 56.5-189.4-7.3 2.1-4.2-11-18.3 0-31.4 25.1-74.8 11.5-93.1-16.2-2.6-3.6-6.3 18.3-11 17.3z" fill="#736357" fill-rule="evenodd"/>
  38   <g stroke-linecap="round" stroke-linejoin="round">
  39     <path d="m91.34 478.6s-136.51 11.5-53.87 119.2" fill="none" stroke="blue" stroke-width="11.9244"/>
  40     <path d="m64.14 587.4c10.46 13 3.14 20.9-9.41 31.3-13.08 10-19.88 15.7-30.34 2.7-9.94-12.6-6.27-20.4 6.8-30.9 12.55-9.9 23.01-15.7 32.95-3.1z" fill="#e6c8aa" stroke-width="2"/>
  41     <path d="m123.2 610.4s-34.48 11.5-24.02 91.5l-33.47 4.2" fill="none" stroke="blue" stroke-width="11.9244"/>
  42     <path d="m244.1 486.4s136.5 11.5 53.8 119.8" fill="none" stroke="blue" stroke-width="11.9244"/>
  43     <path d="m270.7 595.7c-9.9 12.6-2.6 20.4 10 30.9 13 10.4 19.8 15.7 29.8 3.1 10.4-13.1 6.2-20.9-6.3-30.8-13.1-10.5-23-16.3-33.5-3.2z" fill="#e6c8aa" stroke-width="2"/>
  44     <path d="m199.6 604.1s34.5 11.5 24.1 91.5l30.8 10.5" fill="none" stroke="blue" stroke-width="11.9244"/>
  45   </g>
  46   <path d="m8.178 700.3c-5.753-7.8 35.042-700.274 35.042-700.274l253.68 99.894 37.1 605.68z" fill="none"/>
  47   <path d="m115.4 404.8c46.5 67.5 22.5 115.1 49.2 165.8 8.3-63.8 28.7-108.2 60.6-161.6z" fill="#e6c8aa" fill-rule="evenodd"/>
  48 </svg>
  49 SVG
  50 # }}}
  51 
  52 readarray -t colors < <(
  53     convert $b -resize 5% -colors 6 -unique-colors txt: |
  54     awk -F '[ ]+' 'NR > 1 { print $3 }'
  55 )
  56 
  57 sed -i "
  58     s/#ff0000\|red/${colors[0]}/Ig
  59     s/#00ff00\|green/${colors[1]}/Ig
  60     s/#ffff00\|yellow/${colors[2]}/Ig
  61     s/#0000ff\|blue/${colors[3]}/Ig
  62     s/#ff00ff\|magenta/${colors[4]}/Ig
  63     s/#00ffff\|cyan/${colors[5]}/Ig
  64 
  65     s/#f00\|red/${colors[0]}/Ig
  66     s/#0f0\|green/${colors[1]}/Ig
  67     s/#ff0\|yellow/${colors[2]}/Ig
  68     s/#00f\|blue/${colors[3]}/Ig
  69     s/#f0f\|magenta/${colors[4]}/Ig
  70     s/#0ff\|cyan/${colors[5]}/Ig
  71 " $f.svg
  72 
  73 rsvg-convert -aw $w      $f.svg > $f.png ||
  74 convert -background none $f.svg   $f.png
  75 
  76 convert $f.png -background none \
  77 -resize ${w}x${h} -sharpen 1 $f.png
  78 
  79 sw=${r%x*}
  80 iw=$(identify -format '%w' $f.png)
  81  x=$(( x + w / 2 - iw / 2 ))
  82 
  83 (( x < sw / 2 - iw )) &&
  84 convert $f.png -flop $f.png
  85 
  86 convert -size $r xc:none -depth 8 \
  87 $f.png -geometry +$x+$y -composite $f.png
  88 
  89 hsetroot -fill $b -fill $f.png