summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-25 18:48:32 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-25 18:48:32 +0100
commitf12a78597a7056b2f51ce908fb51d1d14d1e176c (patch)
treedfa22e541f41677a2393f95e7730efe8f6a4b19f
parentupdate todo (diff)
downloadblueshift-f12a78597a7056b2f51ce908fb51d1d14d1e176c.tar.gz
blueshift-f12a78597a7056b2f51ce908fb51d1d14d1e176c.tar.bz2
blueshift-f12a78597a7056b2f51ce908fb51d1d14d1e176c.tar.xz
add example that can be used from xmobar
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile3
-rw-r--r--examples/xmobar31
2 files changed, 33 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 103035f..0a3540a 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,8 @@ PYFILES = __main__.py colour.py curve.py monitor.py solar.py icc.py adhoc.py
# Library files
CBINDINGS = $(foreach B,$(SERVER_BINDINGS),blueshift_$(B).so)
# Configuration script example files
-EXAMPLES = comprehensive sleepmode crtc-detection crtc-searching logarithmic
+EXAMPLES = comprehensive sleepmode crtc-detection crtc-searching logarithmic \
+ xmobar
# Build rules
diff --git a/examples/xmobar b/examples/xmobar
new file mode 100644
index 0000000..a262aa4
--- /dev/null
+++ b/examples/xmobar
@@ -0,0 +1,31 @@
+# -*- python -*-
+
+# This example can be used in xmobar to display the
+# Sun's elevation and to what degree it is day time.
+
+
+# Geographical coodinates.
+# (KTH building D computer laboratories in this example.)
+latitude, longitude = 59.42430, 17.83521
+
+# The colour temperature at day and at night.
+temperature_day, temperature_night = 6500, 3700
+
+
+# The visibility of the Sun.
+dayness = sun(latitude, longitude)
+
+# The Sun's elevation.
+elevation = solar_elevation(latitude, longitude)
+
+
+# Calculation of the whitepoint with adjusted colour temperature.
+temperature_now = temperature_day * dayness + temperature_night * (1 - dayness)
+whitepoint = divide_by_maximum(cmf_10deg(temperature_now))
+whitepoint = [('0' + hex(int(c * 255 + 0.5))[2:].upper())[-2:] for c in whitepoint]
+whitepoint = whitepoint[0] + whitepoint[1] + whitepoint[2]
+
+
+# Print information.
+print('<fc=#%s>%.1f</fc>° (%.2f%%)' % (whitepoint, elevation, dayness))
+