temperature-color v2.0.1
Temperature Color
A function for generating colors associated with temperature within a range. View Demo
Description
Temperature Color is a function that generates a color associated with a temperature withing a range. The range is a mapping of checkpoint temperature numbers with a color, and is defined along with the function.
Getting Started
Dependencies
Installing
npm i temperature-color
- In your projects's
package.json
file, add{ ..., "type": "module" }
Usage
import TempColorMapping, { RGB } from 'temperature-color';
const Mapping = TempColorMapping(); // default mapping
const Example1 = Mapping.TemperatureToColor(30);
console.log(Example1); // returns RBG { r: 255, g: 14, b: 0 }
console.log(Example1.toString()); // returns "rgb(255, 14, 0)"
console.log(Example1.toHexString()); // returns "#ff0e00"
const colors = [
[255, 0, 255],
[128, 0, 128],
[135, 206, 235],
[255, 255, 0],
[255, 36, 0],
[139, 0, 0],
]; // [r, g, b]
const temperatures = [-7, -1, 4, 10, 16, 21]; // °C
const Mapping1 = TempColorMapping(colors, temperatures); // custom mapping
const Example2 = Mapping1.TemperatureToColor(3);
console.log(Example2); // returns RGB { r: 133, g: 164, b: 213 }
console.log(Example2.toString()); // returns "rgb(133, 164, 213)"
console.log(Example2.toHexString()); // returns "#85a4d5"
const Example3 = new RGB(3, 40, 69); // color in rgb format
console.log(Example3.totring()); // returns "rgb(3, 40, 69)"
console.log(Example3.toHexString()); // returns "#032845"
Default Mapping (°C) -
Sample Use
Sample use in projects.
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Authors
Abdulsalam Odetayo @linkedIn
License
Distributed under the MIT License. See LICENSE
for more information.