E1M1 Posted June 11, 2009 Posted June 11, 2009 Is there better way to write that function? I know there is always better way to make that script. But I ran out of ideas :S Func _InvertColor($iColor, $mode = 2) $iColor = String(Hex($iColor, 6)) If $mode = 0 Then $RColor = StringTrimLeft(StringTrimRight($iColor, 4), 0) $GColor = StringTrimLeft(StringTrimRight($iColor, 2), 2) $BColor = StringTrimLeft(StringTrimRight($iColor, 0), 4) $InvertedRColor = Hex(255 - Dec($RColor), 2) $InvertedGColor = Hex(255 - Dec($GColor), 2) $InvertedBColor = Hex(255 - Dec($BColor), 2) ElseIf $mode = 1 Then $InvertedBColor = StringTrimLeft(StringTrimRight($iColor, 4), 0) $InvertedGColor = StringTrimLeft(StringTrimRight($iColor, 2), 2) $InvertedRColor = StringTrimLeft(StringTrimRight($iColor, 0), 4) ElseIf $mode = 2 Then $BColor = StringTrimLeft(StringTrimRight($iColor, 4), 0) $GColor = StringTrimLeft(StringTrimRight($iColor, 2), 2) $RColor = StringTrimLeft(StringTrimRight($iColor, 0), 4) $InvertedRColor = Hex(255 - Dec($RColor), 2) $InvertedGColor = Hex(255 - Dec($GColor), 2) $InvertedBColor = Hex(255 - Dec($BColor), 2) EndIf $InvertColor = $InvertedRColor & $InvertedGColor & $InvertedBColor Return "0x" & $InvertColor EndFunc ;==>_InvertColor edited
weaponx Posted June 11, 2009 Posted June 11, 2009 ConsoleWrite(_InvertColor(0x000000)) Func _InvertColor($iColor) Return 0xFFFFFF - $icolor EndFunc ;==>_InvertColor
martin Posted June 11, 2009 Posted June 11, 2009 (edited) ConsoleWrite(_InvertColor(0x000000)) Func _InvertColor($iColor) Return 0xFFFFFF - $icolor EndFunc ;==>_InvertColor I don't think that will work, or at least not very often. Sorry misunderstood what was happening there, it's nice and simple. There are some approaches in this thread. Edited June 11, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
E1M1 Posted June 11, 2009 Author Posted June 11, 2009 ConsoleWrite(_InvertColor(0x000000)) Func _InvertColor($iColor) Return 0xFFFFFF - $icolor EndFunc ;==>_InvertColor it returns lightblue (blue + green) from red edited
Malkey Posted June 11, 2009 Posted June 11, 2009 Try this. expandcollapse popup; Local $col = 0x7AB809 ConsoleWrite(_InvertColor($col, 0) & @CRLF) ConsoleWrite(_InvertColor($col, 1) & @CRLF) ConsoleWrite(_InvertColor($col, 2) & @CRLF & @CRLF) ConsoleWrite(_InvertColorA($col, 0) & @CRLF) ConsoleWrite(_InvertColorA($col, 1) & @CRLF) ConsoleWrite(_InvertColorA($col, 2) & @CRLF) Func _InvertColor($iColor, $mode = 0) Switch $mode Case 0 Return "0x" & Hex(0xFFFFFF - $iColor, 6) Case 1 Return "0x" & StringRegExpReplace(Hex($iColor, 6), "(.{2})(.{2})(.{2})", "\3\2\1") Case 2 Return "0x" & StringRegExpReplace(Hex(0xFFFFFF - $iColor, 6), "(.{2})(.{2})(.{2})", "\3\2\1") EndSwitch EndFunc ;==>_InvertColor Func _InvertColorA($iColor, $mode = 2) $iColor = String(Hex($iColor, 6)) If $mode = 0 Then $RColor = StringTrimLeft(StringTrimRight($iColor, 4), 0) $GColor = StringTrimLeft(StringTrimRight($iColor, 2), 2) $BColor = StringTrimLeft(StringTrimRight($iColor, 0), 4) $InvertedRColor = Hex(255 - Dec($RColor), 2) $InvertedGColor = Hex(255 - Dec($GColor), 2) $InvertedBColor = Hex(255 - Dec($BColor), 2) ElseIf $mode = 1 Then $InvertedBColor = StringTrimLeft(StringTrimRight($iColor, 4), 0) $InvertedGColor = StringTrimLeft(StringTrimRight($iColor, 2), 2) $InvertedRColor = StringTrimLeft(StringTrimRight($iColor, 0), 4) ElseIf $mode = 2 Then $BColor = StringTrimLeft(StringTrimRight($iColor, 4), 0) $GColor = StringTrimLeft(StringTrimRight($iColor, 2), 2) $RColor = StringTrimLeft(StringTrimRight($iColor, 0), 4) $InvertedRColor = Hex(255 - Dec($RColor), 2) $InvertedGColor = Hex(255 - Dec($GColor), 2) $InvertedBColor = Hex(255 - Dec($BColor), 2) EndIf $InvertColor = $InvertedRColor & $InvertedGColor & $InvertedBColor Return "0x" & $InvertColor EndFunc ;==>_InvertColorA ;
weaponx Posted June 11, 2009 Posted June 11, 2009 (edited) it returns lightblue (blue + green) from red I'm not sure if you're saying it's wrong but it works for me.Red 0xff0000 -> Cyan 0x00ffffGreen 0x00ff00 -> Magenta 0xff00ffBlue 0x0000ff -> Yellow 0xffff00 Edited June 11, 2009 by weaponx
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