help with script to calculate variation HEX RGB

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

help with script to calculate variation HEX RGB

Post by ibieel » 04 Oct 2022, 13:48

hey guys, I'm wanting to create a script in which I input 2 colors and the script return the variation (0 to 255) between the two colors in each spectrum of "RGB". :headwall:
can anybody help me?

User avatar
Spawnova
Posts: 554
Joined: 08 Jul 2015, 00:12
Contact:

Re: help with script to calculate variation HEX RGB

Post by Spawnova » 04 Oct 2022, 15:38

You can use some bitwise operations to get the individual rgb components then do some subtraction

Code: Select all

color1 := 0x123456
color2 := 0x654321

r := abs(((color1&0xFF0000)>>16) - ((color2&0xFF0000)>>16))
g := abs(((color1&0xFF00)>>8) - ((color2&0xFF00)>>8))
b := abs((color1&0xFF) - (color2&0xFF))

msgbox % "Variations:`nRed: " r "`nGreen: " g "`nBlue: " b

User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

Re: help with script to calculate variation HEX RGB

Post by ibieel » 04 Oct 2022, 18:04

Spawnova wrote:
04 Oct 2022, 15:38
You can use some bitwise operations to get the individual rgb components then do some subtraction

Code: Select all

color1 := 0x123456
color2 := 0x654321

r := abs(((color1&0xFF0000)>>16) - ((color2&0xFF0000)>>16))
g := abs(((color1&0xFF00)>>8) - ((color2&0xFF00)>>8))
b := abs((color1&0xFF) - (color2&0xFF))

msgbox % "Variations:`nRed: " r "`nGreen: " g "`nBlue: " b
interesting, I had some doubts in this code, can you help me?
1- why did you put "&0xFF0000" as a math operation?
2- what does ">>" mean?
3- why did you use "16" in R and "8" in green and none in blue
4- why was it changing from "0xFF0000" to "0xFF" to BLUE?

Post Reply

Return to “Ask for Help (v1)”