public colorRgb Disc_Value_To_Color() { colorRgb X = new colorRgb(); double indx = 0; if (s < sMin) { indx = 0; } else if (s > sMax || (s - sMax < .000001 && sMax - s < -.000001) || (sMax - s < .000001 && s - sMax < -.000001)) { indx = colors.Length - 1; } else { double x = (sMax - sMin), y = (s - sMin), z = y * colors.Length; if (x == 0) { x = 1; } indx = (float)z / (float)x; } indx = Math.Min(Math.Floor(indx), 4); X.R = colors[(int)indx].R; X.G = colors[(int)indx].G; X.B = colors[(int)indx].B; return(X); }
public colorRgb Cont_Value_To_Color() { colorRgb X = new colorRgb(); if (s < sMin) { X.R = colors[0].R; X.G = colors[0].G; X.B = colors[0].B; } else if (s > sMax || (s - sMax < .000001 && sMax - s < -.000001) || (sMax - s < .000001 && s - sMax < -.000001)) { X.R = colors[colors.Length - 1].R; X.G = colors[colors.Length - 1].G; X.B = colors[colors.Length - 1].B; } else { double range = ((float)sMax - (float)sMin) / (colors.Length - 1); if (range == 0) { range = 1; } double deltaS = (s - sMin) / range; // nsbtha mn el color range kolo int indx = Math.Min((int)Math.Floor(deltaS), 3); double perc = deltaS - indx; // nsbtha mn el range (2 colors) ely hya feh bs X.R = ((colors[indx].R) + perc * (colors[indx + 1].R - colors[indx].R)); X.G = ((colors[indx].G) + perc * (colors[indx + 1].G - colors[indx].G)); X.B = ((colors[indx].B) + perc * (colors[indx + 1].B - colors[indx].B)); } return(X); }
public void Colorize(double ss) { s = ss; if (sMin > sMax) { double temp = sMin; sMin = sMax; sMax = temp; } X = new colorRgb(); if (Dis_radio.Checked == true) { X = Disc_Value_To_Color(); } else { X = Cont_Value_To_Color(); } }