The negative of a symbolic font character (Solved)

Moderator: Forum moderators

Post Reply
User avatar
666philb
Posts: 429
Joined: Thu Jul 09, 2020 3:18 pm
Location: wales uk
Has thanked: 111 times
Been thanked: 146 times

The negative of a symbolic font character (Solved)

Post by 666philb »

I have a script that shows the moon phase on conky.
It runs at startup and prints the result as a font from 'font Symbola' (included in fossa) to a config file, this is then read by conky.

Code: Select all

curl wttr.in/London?format=%m > /root/.config/moonphasec

it all works well but i find the font the wrong way around.
the result is this

Screenshot(9).png
Screenshot(9).png (12.03 KiB) Viewed 1300 times

but the dark area is actually the moon phase and the white area is dark area.
is there someway to invert this ? i know it's easy from an image but this is a font.

this is the actual font 🌒

Last edited by 666philb on Wed Mar 09, 2022 8:02 am, edited 1 time in total.
User avatar
JakeSFR
Posts: 254
Joined: Wed Jul 15, 2020 2:23 pm
Been thanked: 124 times

Re: the negative of a symbolic font character

Post by JakeSFR »

Hmm, that's how this glyph (f0 9f 8c 92) actually looks like and I agree that somebody should be fired. ;)
The other one is an emoji, rendered by the browser; they've "fixed" it, apparently.
I use Unifont instead of Symbola, btw.

Anyway, it's possible to "invert" them 8 codepoints: 0x1f311 (127761) - 0x1f318 (127768), because the first 4 are basically inversions of the last 4, so we just need to add 4 to any of them and wrap around, when necessary.
For example (with a help of https://stackoverflow.com/a/14416133):

Code: Select all

incr=4; xmin=127761; xmax=127769; printf "%b" \\U$(printf '%x\n' $(echo $(( ((($(printf "%d\n" "'$(curl wttr.in/London?format=%m 2>/dev/null)") + incr - xmin) % (xmax - xmin)) + (xmax - xmin)) % (xmax - xmin) + xmin ))))
wttr_moon.gif
wttr_moon.gif (30.89 KiB) Viewed 1277 times

EDIT: here's a nice Bash script I found to calculate and show the current moonphase:

Greetings!

[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
User avatar
666philb
Posts: 429
Joined: Thu Jul 09, 2020 3:18 pm
Location: wales uk
Has thanked: 111 times
Been thanked: 146 times

Re: the negative of a symbolic font character

Post by 666philb »

thanks @JakeSFR for this magical voodoo scripting :)

that bash script is also very clever so no need to use wttr.in now

mooncorrect.png
mooncorrect.png (14.63 KiB) Viewed 1232 times
User avatar
rockedge
Site Admin
Posts: 5714
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1994 times
Been thanked: 2097 times
Contact:

Re: SOLVED the negative of a symbolic font character

Post by rockedge »

Fun little script! Suddenly thinking a little GUI to output a little image of the phase........

Screenshot_2022-03-09_06-59-56.png
Screenshot_2022-03-09_06-59-56.png (276.63 KiB) Viewed 1193 times
User avatar
666philb
Posts: 429
Joined: Thu Jul 09, 2020 3:18 pm
Location: wales uk
Has thanked: 111 times
Been thanked: 146 times

Re: The negative of a symbolic font character (Solved)

Post by 666philb »

for anyone interested this is my script in /root/Startup that writes the config file for conky to read. (@JakeSFRs new version that doesn't use wittr.in not implemented yet)

Code: Select all

#!/bin/sh
sleep 60
incr=4; xmin=127761; xmax=127769; printf "%b" \\U$(printf '%x\n' $(echo $(( ((($(printf "%d\n" "'$(curl wttr.in/London?format=%m 2>/dev/null)") + incr - xmin) % (xmax - xmin)) + (xmax - xmin)) % (xmax - xmin) + xmin )))) > /root/.config/moonphasec

edit: the none wittr.in version (put in /root/Startup)

Code: Select all

#!/bin/bash

moon=`moonphase(){
  local lp=2551443
  local now=$(date -u +"%s")
  local newmoon=592500
  local phase=$((($now - $newmoon) % $lp))
  local phase_number=$((((phase / 86400) + 1)*100000))

  # Multiply by 100000 so we can do integer comparison.  Go Bash!

  if   [ $phase_number -lt 184566 ];  then phase_icon="○"  # new
  elif [ $phase_number -lt 553699 ];  then phase_icon="❩"  # waxing crescent
  elif [ $phase_number -lt 922831 ];  then phase_icon="◗"  # first quarter
  elif [ $phase_number -lt 1291963 ];  then phase_icon="◑"  # first quarter
  elif [ $phase_number -lt 1661096 ]; then phase_icon="●"  # full
  elif [ $phase_number -lt 2030228 ]; then phase_icon="◐"  # waning gibbous
  elif [ $phase_number -lt 2399361 ]; then phase_icon="◖"  # last quarter
  elif [ $phase_number -lt 2768493 ]; then phase_icon="❨"  # waning crescent
  else
    phase_icon="○"  # new
  fi
  echo $phase_icon

}

moonphase`

echo $moon > /root/.config/moonphasec

and to add it to conky

Code: Select all

${font Symbola:size=40}${exec cat /root/.config/moonphasec}${font Dejavu Sans Mono:size=12}
Post Reply

Return to “REQUESTS”