I'm using react-native-color-wheel to generate a color wheel.
I have the following code:
<ColorWheel
initialColor="#ffffff"
onColorChange={color => console.log({color})}
style={{ width: Dimensions.get('window').width }}
thumbStyle={{ height: 30, width: 30, borderRadius: 30 }}
/>
The color is logged but as a HSV value like {h:-120,s:100,v:100}
(corresponds to Blue on the wheel). But I need a RGB instead. I've attempted, unsuccessfully, to use colorsys, like this:
onColorChange={color => {
var rgb = colorsys.hsvToRgb({color});
console.log({rgb})
}}
Logged: {r:null,g:null,b:null}
Why do I get null
values?
link in this comment with slight modification to let you enter each value independently or all at once as an object
This code expects 0 <= h, s, v <= 1, if you're using degrees or radians, remember to divide them out.
The returned 0 <= r, g, b <= 255 are rounded to the nearest Integer. If you don't want this behaviour remove the Math.rounds from the returned object.
And the reverse (with less division)
This code will output 0 <= h, s, v <= 1, but this time takes any 0 <= r, g, b <= 255 (does not need to be an integer)
For completeness,
All of these values should be in the range 0 to 1. For HSL<->RGB go via HSV.