From 2506f732294fb689ed5fe5519119754dcf918087 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 20 Mar 2014 10:12:14 +0100 Subject: add weather demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/comprehensive | 2 +- examples/weather | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 examples/weather (limited to 'examples') diff --git a/examples/comprehensive b/examples/comprehensive index 8c6b45d..8ec121d 100644 --- a/examples/comprehensive +++ b/examples/comprehensive @@ -3,7 +3,7 @@ # This example covers most of what Blueshift offers. For a complete # coverage of Blueshift complement this example with: # backlight, crtc-detection, crtc-searching, logarithmic, -# stored-settings, modes, textconf +# stored-settings, modes, textconf, weather # However the are features that are only covered by the info manual: # Methods for calculating correlated colour temperature diff --git a/examples/weather b/examples/weather new file mode 100644 index 0000000..5291fb6 --- /dev/null +++ b/examples/weather @@ -0,0 +1,71 @@ +# -*- python -*- + +# This example demonstrates how to include weather conditions +# in you configuration scripts. + + +# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) +# +# Permission is granted to copy, distribute and/or modify this document +# under the terms of the GNU Free Documentation License, Version 1.3 +# or any later version published by the Free Software Foundation; +# with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +# You should have received a copy of the GNU General Public License +# along with this software package. If not, see . + + +# Geographical coodinates. +# ("Kristall, vertikal accent i glas och stål" (Crystal, vertical accent +# in glass and steal) in this example. A glas obelisk, lit from the inside +# with adjustable colours and a default colour of 5600 K, in the middle +# of a hyperelliptic roundabout.) +latitude, longitude = 59.3326, 18.0652 + +# International Civil Aviation Organization (ICAO) +# code of the nearest airport. +# (Stockholm Bromma Airport in this example.) +airport = 'ESSB' + +# The colour temperature at day and at night. +temperature_day, temperature_night = 6500, 3700 + +# Dayness modifiers based on weather and sky conditions. +modifiers = { 'clear' : 1.00 + , 'mostly clear' : 0.95 + , 'partly cloudy' : 0.90 + , 'mostly cloudy' : 0.85 + , 'overcast' : 0.80 + , 'obscured' : 0.75 + } + +# The maximum for visibility range for when to +# account for the visibility range. +visibility_max = 4 + + +# The visibility of the Sun. +dayness = sun(latitude, longitude) + +# Get weather report. +metar = weather(airport) + +# Account for weather. +if metar is not None: + conditions = [metar[0]] + metar[2] + for condition in conditions: + if condition in modifiers: + dayness *= modifiers[condition] + _bound, visibility = metar[1] + if (visibility_max is not None) and (visibility is not None): + if visibility < visibility_max: + dayness *= visibility / visibility_max + +# Calculation of the colour temperature. +temp = temperature_day * dayness + temperature_night * (1 - dayness) + +## Calculate the whitepoint with adjusted colour temperature. +whitepoint = temperature(temp, lambda t : divide_by_maximum(cmf_10deg(t))) + +# Apply adjustments. +randr(0) + -- cgit v1.2.3-70-g09d2