* Init event of the form - prepare color arrays HLSMAX = 480 * it is recommended to make BaseColours and ShadowColours divisible by 6 and number of Brightnesses is an even number. BaseColours = 24 ShadowColours = 12 Brightnesses = 32 * aC are colours, aN - appropriate RGB representation of them in character string public array aC(Brightnesses-1,BaseColours+ShadowColours+1), aN(Brightnesses-1,BaseColours+ShadowColours+1) * prepare base (rainbow) colors * note that we skip the 0 and 32 brightness to do not show RGB(0,0,0) and RGB(255,255,255) in all 24 columns in the first row for Hue = 1 to BaseColours for Lum = 1 to Brightnesses - 1 nColor = this.HLStoRGB( (Hue-1)*(HLSMAX/BaseColours ), Lum*(HLSMAX/Brightnesses ), HLSMAX-abs(Lum*(HLSMAX/Brightnesses)*2 - HLSMAX)) aC[Lum, Hue] = nColor aN[Lum, Hue] = allt(str(nColor % 256)) + "," + ; allt(str(int(nColor/256) % 256)) + "," + allt(str(int(nColor/65536) % 256)) endfor endfor * prepare other (shadow) colors for Sat = BaseColours+1 to BaseColours + ShadowColours for Lum = 1 to Brightnesses - 1 nColor = this.HLStoRGB( (Sat-BaseColours-1)*(HLSMAX/ShadowColours ), Lum*(HLSMAX/Brightnesses ), abs(Lum*(HLSMAX/Brightnesses )*2 - HLSMAX)) aC[Lum, Sat] = nColor aN[Lum, Sat] = allt(str(nColor % 256)) + "," + ; allt(str(int(nColor/256) % 256)) + "," + allt(str(int(nColor/65536) % 256)) endfor endfor * prepare greyscale colors. Note the difference - to show black and white colours we divide brightness by another way for Lum = 1 to Brightnesses - 1 nColor = min((Lum-1) * (256/(Brightnesses-2)),255) nColor = RGB(nColor,nColor,nColor) aC[Lum, BaseColours+ShadowColours+1] = nColor aN[Lum, BaseColours+ShadowColours+1] = allt(str(nColor % 256)) + "," + ; allt(str(int(nColor/256) % 256)) + "," + allt(str(int(nColor/65536) % 256)) endfor * prepare cursor and grid to display colours for i=1 to Brightnesses - 1 insert into aaa values(i) endfor go top in aaa with this.Grid1 .ColumnCount = BaseColours+ShadowColours+1 for i = 1 to .ColumnCount .columns(i).ControlSource = "aN[aaa.nIndex," + allt(str(i)) + "]" .columns(i).DynamicBackColor = "aC[aaa.nIndex," + allt(str(i)) + "]" .columns(i).Sparse = .T. endfor endwith
* HLStoRGB method lparameters hue, lum, sat local RR, GG, BB local Magic1, Magic2 local HLSMAX, RGBMAX HLSMAX = 480 RGBMAX = 256 if sat=0 store int((lum*RGBMAX)/HLSMAX) to RR,GG,BB else if lum <= int(HLSMAX/2) Magic2 = int((lum*(HLSMAX + sat) + int(HLSMAX/2)) / HLSMAX) else Magic2 = lum + sat - int(((lum*sat) + int(HLSMAX/2))/HLSMAX) endif Magic1 = 2*lum-Magic2 RR = int((this.HueToRGB(Magic1,Magic2,hue+int(HLSMAX/3))*RGBMAX + int(HLSMAX/2))/HLSMAX) GG = int((this.HueToRGB(Magic1,Magic2,hue)*RGBMAX + (HLSMAX/2)) / HLSMAX) BB = int((this.HueToRGB(Magic1,Magic2,hue-int(HLSMAX/3))*RGBMAX + int(HLSMAX/2))/HLSMAX) endif return RGB(min(RR,255),min(GG,255),min(BB,255))
* HUEtoRGB method lparameters n1,n2,hue local HLSMAX HLSMAX = 480 if hue < 0 hue = hue + HLSMAX endif if hue > HLSMAX hue = hue - HLSMAX endif if (hue < int(HLSMAX/6)) return ( n1 + int(((n2-n1)*hue+int(HLSMAX/12))/int(HLSMAX/6)) ) endif if (hue < int(HLSMAX/2)) return ( n2 ) endif if (hue < int((HLSMAX*2)/3)) return ( n1 + int(((n2-n1)*(int((HLSMAX*2)/3)-hue)+int(HLSMAX/12))/(HLSMAX/6)) ) else return ( n1 ) endif>>As I said, try to find a formula to convert Hue/Sat/Lum parameters for color to RGB. This will give you a smooth colours approach.