Created
August 8, 2021 14:33
-
-
Save su8ru/7ee63975dcb4574c5fe285b7e426429c to your computer and use it in GitHub Desktop.
サーモグラフィ風の色変化をシグモイド関数で再現する - Qiita https://qiita.com/masato_ka/items/c178a53c51364703d70b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* サーモグラフィ風の色変化をシグモイド関数で再現する - Qiita | |
* https://qiita.com/masato_ka/items/c178a53c51364703d70b | |
*/ | |
const gain = 10; | |
const offsetX = 0.2; | |
const offsetGreen = 0.6; | |
const sigmoid = (_x: number, _gain = 1, _offsetX = 0) => | |
(Math.tanh(((_x + _offsetX) * _gain) / 2) + 1) / 2; | |
export const thermographyRGB = (_x: number): [number, number, number] => { | |
const x = _x * 2 - 1; | |
const r = sigmoid(x, gain, offsetX * -1); | |
const b = 1 - sigmoid(x, gain, offsetX); | |
const g = sigmoid(x, gain, offsetGreen) - sigmoid(x, gain, offsetGreen * -1); | |
return [r, g, b]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment