A Python Program to Display ASCII Art Moon Phases
Posted by Al Sweigart in misc
I created a Python terminal program that displays an ASCII art moon at the current moon phase. There are several command line arguments for changing the size, phase, or other properties. You can install it with pip install ascii_moon_phase and explore the source in the git repo. I used LLMs to port it to Rust for a static binary.
.........@@@@@
...............@@@@@@@@@
...................@@@@@@@@@@@
......................@@@@@@@@@@@@
........................@@@@@@@@@@@@@@
..........................@@@@@@@@@@@@@@
...........................@@@@@@@@@@@@@@@
............................@@@@@@@@@@@@@@@@
.............................@@@@@@@@@@@@@@@@@
..............................@@@@@@@@@@@@@@@@
...............................@@@@@@@@@@@@@@@@@
...............................@@@@@@@@@@@@@@@@@
...............................@@@@@@@@@@@@@@@@@
...............................@@@@@@@@@@@@@@@@@
..............................@@@@@@@@@@@@@@@@
.............................@@@@@@@@@@@@@@@@@
............................@@@@@@@@@@@@@@@@
...........................@@@@@@@@@@@@@@@
..........................@@@@@@@@@@@@@@
........................@@@@@@@@@@@@@@
......................@@@@@@@@@@@@
...................@@@@@@@@@@@
...............@@@@@@@@@
.........@@@@@
I used an LLM to generate the original version, and then cleaned it up and made minor fixes manually. I was impressed that the LLM got the basics right and successfully added a few of the options with additional prompting. I have the compiled Rust program run whenever I open a new terminal window, just as a nice reminder of what's going on in the starry dynamo in the machinery of night.
You can play an animation in the terminal with the --phases or --future command line flags.
The --help flag output looks like this:
usage: ascii-moon [-h] [--size SIZE] [--hemisphere {north,south}] [--date DATE] [--phase PHASE] [--light-char CHAR]
[--dark-char CHAR] [--empty-char CHAR] [--show-phase] [--phases] [--future] [--lat DEGREES]
Render the lunar phase as filled ASCII art.
options:
-h, --help show this help message and exit
--size SIZE Height in rows (width is 2*size). Default: 24
--hemisphere {north,south}
Orientation: 'north' shows waxing on the right (default).
--date DATE Calendar date YYYY-MM-DD (default: today).
--phase PHASE Phase fraction in [0.0, 1.0]; 0.0=new, 0.5=full, 1.0=new. Overrides --date.
--light-char CHAR Character for illuminated area (default: '@').
--dark-char CHAR Character for dark area (default: '.').
--empty-char CHAR Character outside the disc (default: space).
--show-phase Print the numeric phase after the art.
--phases Animate the full cycle of lunar phases.
--future Animate upcoming lunar phases.