View Single Post
Old 02-11-2020, 01:29 AM   #24
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
Random example of the previous message in ZSH (yeah, I was bored. On the upside, I found a bug in FBInk, so, eeeh ).

Code:
#!/usr/bin/env zsh

# Debug
set -x

# For rint
zmodload zsh/mathfunc

# For screen dimensions & stuff
eval $(fbink -qe)

# Piggyback on default font scaling for a bar height
barHeight=${FONTH}

# Compute bar width as 80% of screen's width
integer barWidth=$(( rint(screenWidth * 0.8) ))

# Tiny bottom margin (1% of screen's height)
integer bottomMargin=$(( rint(screenHeight * 0.001) ))

# Compute the bar's top-left corner coordinates
integer barTop=$(( rint(screenHeight - bottomMargin - barHeight) ))
integer barLeft=$(( rint((screenWidth - barWidth) / 2.) ))

# Colors
frameCol="WHITE"
bgCol="GRAY9"
fillCol="BLACK"

# Draw the frame (and remember the draw area)
# NOTE: Oops, -E + -k was broken until 01aadd1
#       On Kindle, we can just re-use bar* instead anyway ;).
#eval $(fbink -E -b -k top=${barTop},left=${barLeft},width=${barWidth},height=${barHeight} -B ${frameCol})
fbink -q -b -k top=${barTop},left=${barLeft},width=${barWidth},height=${barHeight} -B ${frameCol}

# Draw background bar (given a 1px frame on each side)
integer fillTop=$(( barTop + 1 ))
integer fillLeft=$(( barLeft + 1 ))
integer fillWidth=$(( barWidth - 2 ))
integer fillHeight=$(( barHeight - 2 ))

fbink -q -b -k top=${fillTop},left=${fillLeft},width=${fillWidth},height=${fillHeight} -B ${bgCol}


# Draw progress bar (current reading position at 42%)
readPos=0.42
integer readWidth=$(( rint(fillWidth * readPos) ))

fbink -q -b -k top=${fillTop},left=${fillLeft},width=${readWidth},height=${fillHeight} -B ${fillCol}


# Compute & draw chapter markers
integer tickWidth=$(( rint(screenWidth * 0.0015) ))
chapters=(0.20 0.45 0.72)
for chapter in ${chapters[@]} ; do
	integer tickLeft=$(( rint(fillLeft + (fillWidth * chapter)) ))

	fbink -q -b -k top=${barTop},left=${tickLeft},width=${tickWidth},height=${barHeight} -B ${frameCol}
done


# Compute & draw subchapter markers (square, middle of the bar)
integer tickPx=$(( rint(screenWidth * 0.002) ))
integer tickTop=$(( rint(fillTop + (fillHeight / 2.) - (tickPx / 2.)) ))
chapters=(0.05 0.11 0.30 0.86 0.92)
for chapter in ${chapters[@]} ; do
	integer tickLeft=$(( rint(fillLeft + (fillWidth * chapter)) ))

	fbink -q -b -k top=${tickTop},left=${tickLeft},width=${tickPx},height=${tickPx} -B ${frameCol}
done


# Refresh the bar
#fbink -q -s top=${lastRect_Top},left=${lastRect_Left},width=${lastRect_Width},height=${lastRect_Height}
fbink -q -s top=${barTop},left=${barLeft},width=${barWidth},height=${barHeight}
Should be easy to adapt in Python/Lua/Go, there's nothing fancier than arrays, fp maths and int()/rint() (hence ZSH instead of shell).

Last edited by NiLuJe; 02-11-2020 at 01:35 AM.
NiLuJe is offline   Reply With Quote