Skip to content

Instantly share code, notes, and snippets.

@EDais
EDais / colourTemperature.js
Created August 30, 2017 14:50
JavaScript port of getRGBFromTemperature
"use strict";
const clamp = (num, min, max) => num < min ? min : num > max ? max : num;
/** Given a temperature (in Kelvin), estimate an RGB equivalent
* @param {number} tmpKelvin - Temperature (in Kelvin) between 1000 and 40000
* @returns {{r:number, g:number, b:number}} - RGB channel intensities (0-255)
* @description Ported from: http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
*/
exports.getRGBFromTemperature = function(tmpKelvin) {