From 90d483317e7528b269d597fc0246ccac5fbb6414 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 5 Mar 2014 20:17:43 +0100 Subject: prototype of lunar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/plugins/lunar.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/plugins/lunar.py (limited to 'src/plugins') diff --git a/src/plugins/lunar.py b/src/plugins/lunar.py new file mode 100644 index 0000000..2df7c0c --- /dev/null +++ b/src/plugins/lunar.py @@ -0,0 +1,65 @@ +# -*- python -*- +''' +xpybar – xmobar replacement written in python +Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +''' + +import math +import time + + +def julian_day(t): + ''' + Converts a POSIX time timestamp to a Julian Day timestamp + + @param t:float The time in POSIX time + @return :float The time in Julian Days + ''' + return t / 86400.0 + 2440587.5 + +def radians(deg): + ''' + Convert an angle from degrees to radians + + @param deg:float The angle in degrees + @return :float The angle in radians + ''' + return deg * math.pi / 180 + +ref = julian_day(934329600) # 11 August 1999 00:00:00 UTC +now = julian_day(time.time()) +synodic_month = 29.530588853 + +fraction = ((now - ref) / synodic_month) % 1 +waxing = fraction <= 0.5 # we get an off by one without equality +print('fraction: %f' % fraction) +print('waxing' if waxing else 'waning') + +terminator = 90 - 360 * fraction # sunlit trailing +if terminator < -90: + terminator += 180 # visible side +print('terminator: %f°' % terminator) + +hacoversin = lambda deg : 0.5 - math.sin(radians(deg)) / 2 + +inverted = terminator < 0 +illumination = hacoversin(abs(terminator)) + +if (not waxing) != inverted: + illumination = 1 - illumination + +print('illumination: %.2f%%' % (illumination * 100)) + -- cgit v1.2.3-70-g09d2