2006-11-27

FUNCTION TO CONVERT COLORS

The short function below converts any color to its darker or brighter version, just as the original colorpicker slidebar.

parameters:

      rgb - original rgb value to convert

      tnlevel - ranges from -100 to + 100. zero means no changes; +100 = white; -100 = black; positive values will return brighter images, while negative will bring darker.

 

lparameters tnRgb, tnLevel

if tnLevel = 0
   return tnrgb
endif


tnLevel = tnLevel / 100

local lnRed, lnGreen, lnBlue
lnRed   = bitand(tnRgb, 0x000000ff)
lnGreen = bitrshift(bitand(tnRgb, 0x0000ff00), 8 )
lnBlue  = bitrshift(bitand(tnRgb, 0x00ff0000), 16)


if tnLevel > 0
   return rgb( ;
      lnRed   + ((255 - lnRed)   * tnLevel) , ;
      lnGreen + ((255 - lnGreen) * tnLevel) , ;
      lnBlue  + ((255 - lnBlue)  * tnLevel) )
else
   return rgb( ;
      lnRed   + (lnRed   * tnLevel) , ;
      lnGreen + (lnGreen * tnLevel) , ;
      lnBlue  + (lnBlue  * tnLevel) )
endif


To better understand how it works, you can download the attached file, that contains a simple example. Click on "select color" to pick a color then play with the spinner to see the darker and brighter resulting colors.



1 comment:

  1. Este articulo esta traducido al español en www.PortalFox.com


    "FUNCION PARA CONVERTIR COLORES"

    http://www.portalfox.com/article.php?sid=2301




    ReplyDelete