Jump to content
Sign in to follow this  
smashly

Opposite color function ?

Recommended Posts

smashly

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

Share this post


Link to post
Share on other sites
UEZ

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

Share this post


Link to post
Share on other sites
wakillon

Like this ?

$_OppositeColor = BitXOR ( $_Color, 0xFFFFFF )


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
smashly

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

Share this post


Link to post
Share on other sites
MvGulik

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

Share this post


Link to post
Share on other sites
MvGulik

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

Share this post


Link to post
Share on other sites
wakillon

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

Share this post


Link to post
Share on other sites
UEZ

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

Share this post


Link to post
Share on other sites
smashly

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

Share this post


Link to post
Share on other sites
smashly

Thank You UEZ, I missed your 2nd post, gunna give your func a go.. w00t.

:unsure:

Edited by smashly

Share this post


Link to post
Share on other sites
UEZ

Well, my function does ComplementaryColor in 9 lines but as wakillon wrote one line is enough. :unsure:

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

Share this post


Link to post
Share on other sites
wakillon

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

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  

×