Skip to content

Instantly share code, notes, and snippets.

@jimstudt
jimstudt / UIColor-colorWithKelvin.swift
Created November 15, 2015 20:47
An iOS extension to UIColor to get a white point corresponding to a temperature.
extension UIColor {
// based on http://www.zombieprototypes.com/?p=210 who looked at some data and did a bunch of curve fitting
static func colorWithKelvin( kelvin: CGFloat) -> UIColor {
let k = kelvin < 1000 ? 1000 : ( kelvin > 40000 ? 40000 : kelvin)
func interpolate( value: CGFloat, a: CGFloat, b:CGFloat, c:CGFloat) -> CGFloat {
return a + b*value + c*log(value)
}