Skip to content

Instantly share code, notes, and snippets.

@robnadin
Last active January 22, 2016 11:36
Show Gist options
  • Save robnadin/1a9576b57c5419dd2320 to your computer and use it in GitHub Desktop.
Save robnadin/1a9576b57c5419dd2320 to your computer and use it in GitHub Desktop.
Set brightness based on hour
/* Brightness.swift -- Set brightness based on hour
This file is part of brightness.
Brightness 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.
Brightness 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 Brightness. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2013 Jakub Tymejczyk <tymmej@gmail.com>
*/
import Swift
let TRANSITION_LOW = -6.0
let TRANSITION_HIGH = 3.0
/*also from Redshift*/
func calculate_interpolated_value(elevation: Double, _ day: Float, _ night: Float) -> Float {
var result: Float = 0
if elevation < TRANSITION_LOW {
result = night
} else if elevation < TRANSITION_HIGH {
/* Transition period: interpolate */
let a = Float((TRANSITION_LOW - elevation) / (TRANSITION_LOW - TRANSITION_HIGH))
result = (1.0 - a) * night + a * day
} else {
result = day
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment