summaryrefslogtreecommitdiffstats
path: root/examples/xpybar
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-03 23:02:03 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-03 23:02:03 +0100
commit07e4c58996fe466e221c423dd660febdf225182c (patch)
tree4df6fe8378fd2e1d45f1fc9c4f3c60a473d058ad /examples/xpybar
parentxmobar example: round precents to nearest integer, instead of floor (diff)
downloadblueshift-07e4c58996fe466e221c423dd660febdf225182c.tar.gz
blueshift-07e4c58996fe466e221c423dd660febdf225182c.tar.bz2
blueshift-07e4c58996fe466e221c423dd660febdf225182c.tar.xz
add xpybar port of xmobar example
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--examples/xpybar31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/xpybar b/examples/xpybar
new file mode 100644
index 0000000..b9dc99f
--- /dev/null
+++ b/examples/xpybar
@@ -0,0 +1,31 @@
+# -*- python -*-
+
+# This example can be used in xpybar 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.3472, 18.0728
+
+# 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 = [str(int(c * 255 + 0.5)) for c in whitepoint]
+whitepoint = ';'.join(whitepoint)
+
+
+# Print information.
+print('\033[38;2;%sm%i\033[0mK %.1f° %.0f%%' % (whitepoint, int(temperature_now), elevation, int(dayness * 100)))
+