Jump to content

Recommended Posts

Posted

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

Posted (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 by smashly
Posted

  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 ...
 

Posted (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 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 ...
 

Posted (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 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Thank You all :unsure:

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

Posted

  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. :unsure:

Br,

UEZ

To be fair, 3 lines are necessary ! Posted Image

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.0WIN 8.1 X64 - Other Example Scripts

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...