Find Related products on Amazon

Shop on Amazon

Show HN: Moon Phase Algorithms for C, Lua, Awk, JavaScript, etc.

Published on: 2025-06-11 18:22:32

moonphase - Werewolf Early Warning System A collection of snippets that get the phase of the moon, currently, the implementations are: Systems Level Languages: C/C++ Rust Zig Scripting Languages: Lua JavaScript Python DSLs: awk bc These functions take a time as an input (usually in unix epoch seconds or the languages official way of doing time), and return the "age" of the moon in radians, such that (1-cos(x))/2 returns the illuminated fraction of the moons surface, this indirection is needed because across a full cycle, the same illuminated percent appears more than once, the first and third quarter are a good example. All implementations contain test cases showing how to get the illuminated fraction and percent using the code. When the age of the moon is converted into a range between [0,1] . You can then get the age of the moon in days by multiplying it by ~29.5. You can also get the "index" of the phase, required for the phase name and emoji, with the illuminated fr ... Read full article.