# Providing RGB code

**URL:** <https://mapwindow.discourse.group/t/providing-rgb-code/1403>\
**Category:** MapWinGIS\
**Created:** [August 23, 2022, 7:46pm UTC](https://mapwindow.discourse.group/t/providing-rgb-code/1403 "2022-08-23T19:46:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mickaelschwedler](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/mickaelschwedler/32/666_2.png) [@mickaelschwedler](https://mapwindow.discourse.group/u/mickaelschwedler)\
**Post date:** [August 23, 2022, 7:46pm UTC](https://mapwindow.discourse.group/t/providing-rgb-code/1403/1 "2022-08-23T19:46:11Z")

</div>

// Public-domain function by Darel Rex  
// Finley, 2022.  
//  
// The input values may be from 0 to  
// 1, or from 0 to 255, or any 0-based  
// scale, but all three values must  
// use the same scale. Returns a hue  
// value from 0 to 1. (If hue is  
// undefined, returns 0.)

double RGBtoHue(  
double R, double G, double B) {  
return  
R==G && R==B ? 0. :  
R\>=G && R\>=B ?  
(B\>G ? 6./6.-1./6._(B-G)/(R-G)  
: 0./6.+1./6._(G-B)/(R-B)) :  
G\>=R && G\>=B ?  
(R\>B ? 2./6.-1./6._(R-B)/(G-B)  
: 2./6.+1./6._(B-R)/(G-R)) :  
G\>R ? 4./6.-1./6._(G-R)/(B-R)  
: 4./6.+1./6._(R-G)/(B-G) ; }
