smashly Posted April 18, 2011 Posted April 18, 2011 Hi, Thanks for stopping by to read. I have one of those questions that is probably obvious. Has anyone written a function in Autoit that can generate opposite colors? eg; Supply a color and the function return it's opposite color. I did do a forum search but I couldn't find what I needed. TYIA for any advice or help. Cheers
UEZ Posted April 18, 2011 Posted April 18, 2011 You mean something like 0xFF - $color whereas $color is a value of RGB?Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
wakillon Posted April 18, 2011 Posted April 18, 2011 Like this ? $_OppositeColor = BitXOR ( $_Color, 0xFFFFFF ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
smashly Posted April 18, 2011 Author Posted April 18, 2011 (edited) Hi, Thanks you for taking the time to respond. No I mean opposite color, like Black and White. I wasn't any good at art or color wheels at school. So I have no Idea of how to calculate an opposite color to the color I have. The way I'll be using it is with Text on random colored backdrop. I'd like the text readable, so If I can work out an opposite color to the random backdrop color then I can set my text to the opposite:) Edit: Thank You wakillon, I can't believe I didn't see it.. doh I've used BitXOR when creating Icon masks..lol Cheers Edited April 18, 2011 by smashly
MvGulik Posted April 18, 2011 Posted April 18, 2011 On 4/18/2011 at 8:34 AM, 'wakillon said: Like this ?$_OppositeColor = BitXOR ( $_Color, 0xFFFFFF )mmm, technically your not only flipping the color(hue) here, but also the lightness component of a color. (OP no clear about that part though.) "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
MvGulik Posted April 18, 2011 Posted April 18, 2011 (edited) On 4/18/2011 at 8:45 AM, 'smashly said: The way I'll be using it is with Text on random colored backdrop.I'd like the text readable, so If I can work out an opposite color to the random backdrop color then I can set my text to the opposite:)In that case you might like to handle/use your colors in a different way (color model) -> HSL/HSV/etc instead of RGB Edited April 18, 2011 by singularity "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
wakillon Posted April 18, 2011 Posted April 18, 2011 And like this ? $_Color = 0x000000 $_OppositeColor = '0x' & Hex ( BitXOR ( $_Color, 0xFFFFFF ), 6 ) ConsoleWrite ( "$_OppositeColor : " & $_OppositeColor & @Crlf ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
UEZ Posted April 18, 2011 Posted April 18, 2011 (edited) This one (the long way)? MsgBox(0, "Test", ComplementaryColor(0x1144AA)) Func ComplementaryColor($iRGB) ;coded by UEZ 2011 If $iRGB = "" Then Return SetError(1, 0, 0) $aRGB = StringRegExp(Hex($iRGB, 6), ".{2}", 3) If @error Then Return SetError(2, 0, 0) $aRGB[0] = 0xFF - ("0x" & $aRGB[0]) $aRGB[1] = 0xFF - ("0x" & $aRGB[1]) $aRGB[2] = 0xFF - ("0x" & $aRGB[2]) Return Hex(0x10000 * $aRGB[0] + 0x100 * $aRGB[1] + $aRGB[2], 6) EndFunc Shortest way: MsgBox(0, "Test", Hex(BitXOR(0x1144AA, 0xFFFFFF), 6)) Br, UEZ Edited April 18, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
smashly Posted April 18, 2011 Author Posted April 18, 2011 Thank You all I edited my last post due to I missed wakillon 1st post and it's exactly what I need. Thanks singularity for the suggestion. Thanks wakillon for waking me up ..lol XOR I have used when doing icon masks and I can't believe I didn't think of it. Cheers
smashly Posted April 18, 2011 Author Posted April 18, 2011 (edited) Thank You UEZ, I missed your 2nd post, gunna give your func a go.. w00t. Edited April 18, 2011 by smashly
UEZ Posted April 18, 2011 Posted April 18, 2011 Well, my function does ComplementaryColor in 9 lines but as wakillon wrote one line is enough. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
wakillon Posted April 18, 2011 Posted April 18, 2011 On 4/18/2011 at 9:13 AM, 'UEZ said: Well, my function does ComplementaryColor in 9 lines but as wakillon wrote one line is enough. Br, UEZ To be fair, 3 lines are necessary ! MsgBox ( 0, "Test", _OppositeColor ( 0x000000 ) ) Func _OppositeColor ( $_Color ) Return '0x' & Hex ( BitXOR ( $_Color, 0xFFFFFF ), 6 ) EndFunc ;==> _OppositeColor ( ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
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