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".
can anybody help me?
help with script to calculate variation HEX RGB
Re: help with script to calculate variation HEX RGB
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
Some of my AHK programs: 3D Voxel Game - Platformer Game
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
Re: help with script to calculate variation HEX RGB
interesting, I had some doubts in this code, can you help me?Spawnova wrote: ↑04 Oct 2022, 15:38You 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
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?