Kip Posted September 24, 2008 Posted September 24, 2008 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) CODEFunc 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 MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now