[INFO] Javascript Colors -- HSV 2 RGB conversion

Marielle Lange M.Lange at ed.ac.uk
Tue May 31 17:51:56 EDT 2005


If anyone is interested, the function below converts HSV to RGB format.

It can be found in use in this stack:

go url
"http://revolution.lexicall.org/stacks/education/presentation_tools/skin_colors.rev"

I used it to automatically create components of an interface made of the same
hue, with different saturation and brightness values. The cursor changes the
value for the hue of the first group of 4 color patches. Then, for this first
group, you can change the Saturation and Brightness values.

Enjoy,
Marielle
---------------------------------------------------------


function HSVRGB tH,tS,tV

  put (tH/360) into tH
  put (tS/100) into tS
  put (tV/100) into tV

  if tS is empty then
    put (tV * 255) into tR
    put (tV * 255) into tG
    put (tV * 255) into tB
  else

    put (tH * 6) into vH
    put trunc(vH) into vi
    put (tV * (1 - tS)) into V1
    put (tV * (1 - tS * (vH - Vi))) into V2
    put (tV * (1 - tS * (1 - (vH - Vi)))) into V3

    -- put "vi:" & vi & ";" & tab & cr after message
    -- put v1,v2,v3 & cr after message

    switch vi
    case 0
      put tV into vR
      put v3 into vG
      put v1 into vB
      break
    case 1
      put v2 into vR
      put tv into vG
      put v1 into vB
      break
    case 2
      put V1 into vR
      put tV into vG
      put v3 into vB
      break
    case 3
      put V1 into vR
      put v2 into vG
      put tV into vB
      break
    case 4
      put V3 into vR
      put v1 into vG
      put tV into vB
      break
    default
      put tV into vR
      put v1 into vG
      put v2 into vB
    end switch

    put trunc(vR * 255) into tR
    put trunc(vG * 255) into tG
    put trunc(vB * 255) into tB


  end if

  return tR,tG,tB

end HSVRGB



More information about the use-livecode mailing list