Get the latest tech news

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


A collection of impls to get the current moon phase - oliverkwebb/moonphase

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. All these snippets are based off the algorithm in moontool, a GUI program made in the 80s by John Walker, which based its algorithms off the book Practical Astronomy With Your Calculator.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of javascript

javascript

Photo of lua

lua

Photo of awk

awk

Related news:

News photo

Nova: A JavaScript and WebAssembly engine written in Rust

News photo

Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

News photo

A thought on JavaScript "proof of work" anti-scraper systems