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