Sign in to follow this  
Followers 0
Kip

Some color functions.

1 post in this topic

4 Functions to edit your color codes.

Color_Subtract() ; $iSubtract = Subtracts a number of colors from ech color (red, green and blue)

Color_Add() ; $iAdd = Adds a number of colors to each color (red, green and blue)

Color_Lighter() ; Makes the color $iPercent times lighter (0-100)

Color_Darker() ; Makes the color $iPercent times darker (0-100)

CODE
Func Color_Subtract($iColor, $iSubtract)

$b = BitAND(BitShift($iColor, 16), 0xFF)

$g = BitAND(BitShift($iColor, 8), 0xFF)

$r = BitAND($iColor, 0xFF)

$b = Min($b-$iSubtract, 0)

$g = Min($g-$iSubtract, 0)

$r = Min($r-$iSubtract, 0)

$Hex = Hex($b,2)&Hex($g,2)&Hex($r,2)

Return Dec($Hex)

EndFunc

Func Color_Add($iColor, $iAdd)

$b = BitAND(BitShift($iColor, 16), 0xFF)

$g = BitAND(BitShift($iColor, 8), 0xFF)

$r = BitAND($iColor, 0xFF)

$b = Max($b+$iAdd, 0xFF)

$g = Max($g+$iAdd, 0xFF)

$r = Max($r+$iAdd, 0xFF)

$Hex = Hex($b,2)&Hex($g,2)&Hex($r,2)

Return Dec($Hex)

EndFunc

Func Color_Lighter($iColor, $iPercent)

$b = BitAND(BitShift($iColor, 16), 0xFF)

$g = BitAND(BitShift($iColor, 8), 0xFF)

$r = BitAND($iColor, 0xFF)

$b = Max(((0xFF-$B)/100)*$iPercent+$b, 0xFF)

$g = Max(((0xFF-$g)/100)*$iPercent+$g, 0xFF)

$r = Max(((0xFF-$r)/100)*$iPercent+$r, 0xFF)

$Hex = Hex($b,2)&Hex($g,2)&Hex($r,2)

Return Dec($Hex)

EndFunc

Func Color_Darker($iColor, $iPercent)

$b = BitAND(BitShift($iColor, 16), 0xFF)

$g = BitAND(BitShift($iColor, 8), 0xFF)

$r = BitAND($iColor, 0xFF)

$b = Min($b-(($b/100)*$iPercent), 0)

$g = Min($g-(($g/100)*$iPercent), 0)

$r = Min($r-(($r/100)*$iPercent), 0)

$Hex = Hex($b,2)&Hex($g,2)&Hex($r,2)

Return Dec($Hex)

EndFunc

Func Min($iNumber, $iMin)

If $iNumber < $iMin Then

Return $iMin

Else

Return $iNumber

EndIf

EndFunc

Func Max($iNumber, $iMax)

If $iNumber > $iMax Then

Return $iMax

Else

Return $iNumber

EndIf

EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0