Sebastian Walz 9f7b02e1cd
Tohu vaBohu
2023-04-03 14:38:02 +02:00

27 lines
1.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function rateFullStars ( stars, maximum )
stars = eval(stars)
maximum = eval(maximum)
assert
(
stars ~= nil and maximum ~= nil,
"cannot print full stars: " .. stars .. " " .. maximum
)
full = math.floor(stars*maximum)
rest = maximum - full
tex.print (("\\faStar"):rep(full)..("\\faStarO"):rep(rest))
end
function rateHalfStars ( stars, maximum )
stars = eval(stars)
maximum = eval(maximum)
assert
(
stars ~= nil and maximum ~= nil,
"cannot print half stars: " .. stars .. " " .. maximum
)
full = math.floor(stars*maximum)
rest = math.floor((1-stars)*maximum)
half = maximum - full - rest
tex.print (("\\faStar"):rep(full)..("\\faStarHalfFull"):rep(half)..("\\faStarO"):rep(rest))
end