|
Sub RGB2HSV(Byref hue As Integer,Byref sat As Integer,Byref value As Integer, Byval myrgb As Integer) Dim As Integer max=0,min=255,r,g,b r=(myRGB Shr 16) And &hff g=(myRGB Shr 8) And &hff b=myRGB And &hff If r>max Then max=r If r<min Then min=r If g>max Then max=g If g<min Then min=g If b>max Then max=b If b<min Then min=b value=max '? max, min,Hex(myrgb),r,g,b If max=0 Or max=min Then sat=0:hue=0:Exit Sub sat=255*(1.-(min/max)) If max=r Then hue=60.*(g-b)/(max-min)+IIf(g>=b,0,360) Elseif max=g Then hue=60.*(b-r)/(max-min)+120 Else hue=60.*(r-g)/(max-min)+240 End If End Sub Function HSV2RGB(Byval hue As Integer, Byval sat As Integer,Byval value As Integer )As Integer 'hue 0 TO 359 0=red, 120 green 240 blue 'sat is saturation 0 to 255 0 is neutral grey 255 is full color 'value 0 To 255 is the brightness 0 is black 255 is maximum brightness If sat = 0 Then Return RGB(value,value,value) hue Mod= 360 Dim As Single h1= hue/60 Dim As Integer i = Int(h1) Dim As Single f = frac(h1) Dim As Integer p = value * ( 255 - sat )/256 Dim As Integer q = value * ( 255 - f*sat)/256 Dim As Integer t = value * ( 255 - ( 1. - f )*sat)/256
Select Case As Const i Case 0: Return RGB(value,t,p) Case 1: Return RGB(q,value,p) Case 2: Return RGB(p,value,t) Case 3: Return RGB(p,q,value) Case 4: Return RGB(t,p,value) Case 5: Return RGB(value,p,q) End Select End Function
Screenres 800,600,32 ScreenLock 'increasing value For J As Integer =0 To 255 For I As Integer =0 To 359 Pset (J,i),HSV2RGB(I,255,J) Next Next
'decreasing saturation For J As Integer =0 To 255 For I As Integer =0 To 359 Pset (J+256,i),HSV2RGB(I,255-J,255) Next Next 'one hue ,saturation and value gradient For J As Integer =0 To 255 For I As Integer =0 To 255 Pset (i,j+360),HSV2RGB(0,i,j) Pset (i+256,j+360),HSV2RGB(120,i,j) Pset (i+512,j+360),HSV2RGB(240,i,j) Next Next
'value gradient for saturation 0 For J As Integer =0 To 255 For I As Integer =0 To 255 Pset (I+512,J),HSV2RGB(0,0,j) Next Next
Dim As Integer h,s,v RGB2hsv(h,s,v,HSV2rgb(27,224,25)) Print h,s,v
SCREENUNLOCK Sleep
|