[futurebasic] Re: [FB] Colour Intensity

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 1999 : Group Archive : Group : All Groups

From: Dabs@...
Date: Sun, 24 Oct 1999 15:01:24 EDT
This is probably what you are looking for.  I don't know where I got it 
originally so apologies to the author:

CLEAR LOCAL
'~'
LOCAL FN mixColors(RGB1&,mix,RGB2&)
'~'
SELECT
CASE mix>=255'RGB1& is answer so do nothing
CASE mix<=0
RGB2&;6 = @RGB1&
'BLOCKMOVE RGB2&, RGB1&, _rgbColor'RGB2& is answer
CASE ELSE'mix the two colors
red1% = PEEK(@RGB1&.red%)
gre1% = PEEK(@RGB1&.green%)
blu1% = PEEK(@RGB1&.blue%)
red2% = PEEK(@RGB2&.red%)
gre2% = PEEK(@RGB2&.green%)
blu2% = PEEK(@RGB2&.blue%)
red1% = red1% * mix/255
red2% = red2% * (255 - mix)/255
red1% = red1% + red2%
gre1% = gre1% * mix/255
gre2% = gre2% * (255 - mix)/255
gre1% = gre1% + gre2%
blu1% = blu1% * mix/255
blu2% = blu2% * (255 - mix)/255
blu1% = blu1% + blu2%
RGB1&.red% = red1%<<8
RGB1&.green% = gre1%<<8
RGB1&.blue% = blu1%<<8
END SELECT
END FN



CLEAR LOCAL
DIM RGBcol.rgbColor
'lig - Lightness, 0=black, 127=color, 255=white
'~'
LOCAL FN lightness(RGBptr&,lig)
'~'
IF lig > 255 THEN lig = 255
IF lig < 0 THEN lig = 0
LONG IF lig>127
RGBcol.red% = 255 << 8
RGBcol.green% = 255 << 8
RGBcol.blue% = 255 << 8
mix=(127 - (lig - 127)) << 1
XELSE
RGBcol.red% = 0
RGBcol.green% = 0
RGBcol.blue% = 0
mix = lig << 1
END IF
FN mixColors(RGBptr&,mix,@RGBcol)
END FN


Simply pass the RGB record and the amount to lighten (127-255) or Darken 
(1-126) the color.


David