diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-05 20:17:43 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-05 20:17:43 +0100 |
commit | 90d483317e7528b269d597fc0246ccac5fbb6414 (patch) | |
tree | e23eca47369a873ac5259c463a28f0e18c6993d8 /src | |
parent | update todo (diff) | |
download | xpybar-90d483317e7528b269d597fc0246ccac5fbb6414.tar.gz xpybar-90d483317e7528b269d597fc0246ccac5fbb6414.tar.bz2 xpybar-90d483317e7528b269d597fc0246ccac5fbb6414.tar.xz |
prototype of lunar
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lunar.py | 65 |
1 files changed, 65 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. +''' + +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)) + |