Jump to content

Adding 3 variables together to make a RGB color


mixmax2
 Share

Recommended Posts

can anyone tell me howto do this? im trying to make a color picker in my script and i wanna add 3 sliders, each modify RED, GREEN, or BLUE, and i want an update button that when clicked takes the info from the slider, adds em together like $red+$green+$blue, and then makes em a RGB color code which i can then use to change the color of a label, im extremely new to au3 and the helpfile does not tell me howto add numbers or variables together :lmao: So someone, please help.

Link to comment
Share on other sites

OK, so RGB colors are set up like this: 0x000000 - 0xFFFFFF (0x just means hex). The red portion is the first two numbers (000000 to FF0000), green is the middle two (000000 to 00FF00), and blue is the last two (000000 to 0000FF). So, all you have to do is modify the respective values and add them together.

Example since that was such a crappy explanation:

I want something purple. So I slide my red slider to FF and my blue slider to FF as well. Green stays at 00. So now I have red (FF0000) and blue (0000FF). Add them together and you get FF00FF, which is purple.

Link to comment
Share on other sites

OK, so RGB colors are set up like this: 0x000000 - 0xFFFFFF (0x just means hex). The red portion is the first two numbers (000000 to FF0000), green is the middle two (000000 to 00FF00), and blue is the last two (000000 to 0000FF). So, all you have to do is modify the respective values and add them together.

Example since that was such a crappy explanation:

I want something purple. So I slide my red slider to FF and my blue slider to FF as well. Green stays at 00. So now I have red (FF0000) and blue (0000FF). Add them together and you get FF00FF, which is purple.

i still dont know howto add them together, i know all that, i was asking howto add them together to create a color, literally, not how to do it, but HOW to do it.

Link to comment
Share on other sites

It's just normal addition. Just try the color chooser that gafrost suggested.

thats the problem, the helpfile doesnt tell me howto correctly add things.

under math, it doesnt have addition or subtraction, just a bunch of advanced stuff.

Edited by mixmax2
Link to comment
Share on other sites

The helpfile isn't going to teach you basic addition. That's what school was for.

sigh*, no i dont know howto add in the script, omg, i dont know what to type, to make it add anything together, ive tried adding variables like $1+$2+$3, but it doesnt work, arg its getting extremely hard to explain.

Link to comment
Share on other sites

sigh*, no i dont know howto add in the script, omg, i dont know what to type, to make it add anything together, ive tried adding variables like $1+$2+$3, but it doesnt work, arg its getting extremely hard to explain.

You probably need to tell AutoIt that it is a number and not a string, $Result = Number ($1+$2+$3 )

Edit.. Looking at the post above this is probably not what you need, but I'll leave it just in case!

Edited by ChrisL
Link to comment
Share on other sites

  • Developers

The color is a 6 character hex code like:

0xAABBCC

AA = Red

BB = Green

CC = Blue

If your 3 sliders ($Red,$Green,$Blue) return a decimal value then just do:

$Color = "0x" & Hex($Red) & Hex($Green) & Hex($Blue)

And update a control by doing:

GUICtrlSetColor($YourControl, $Color)

:lmao:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The color is a 6 character hex code like:

0xAABBCC

AA = Red

BB = Green

CC = Blue

If your 3 sliders ($Red,$Green,$Blue) return a decimal value then just do:

$Color = "0x" & Hex($Red) & Hex($Green) & Hex($Blue)

And update a control by doing:

GUICtrlSetColor($YourControl, $Color)

:lmao:

ty so much, this one sounds like itll work, im gonna try it out.

Link to comment
Share on other sites

ty so much, this one sounds like itll work, im gonna try it out.

k this works great, but now can someone tell me another thing? i have 3 sliders, each one represents R, G, B, next to each slider is a input that represents the number, how can i make the input represent what numberthe slider is on AS the slider is being scrolled?
Link to comment
Share on other sites

  • Developers

$number1 = Number( $1dat + $2dat + $3dat )

is this how you add variables?

What is this different from what I posted before ?

Just update the control with the $color value....

EDIT: Or do you want to convert the HEX value back to decimal ?

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

What is this different from what I posted before ?

Just update the control with the $color value....

EDIT: Or do you want to convert the HEX value back to decimal ?

nothing wrong with what you said Jdeb i just think they are under the wrong idea of adding the varibles. not just sticking them together to = 1 varible without addition. example as follows it is normally a newbie mistake.

$a=10
$b=20
$c=30
 now you can go with addition of $z = $a + $b + $c
so the result would be $z = 60
 the other ways is joing them without addition
 $z = $a & $b & $c
so $z = 102030

big difference. what Jdeb said is the easiest in my opinion.

Edited by beerman
Link to comment
Share on other sites

can anyone tell me howto do this? im trying to make a color picker in my script and i wanna add 3 sliders, each modify RED, GREEN, or BLUE, and i want an update button that when clicked takes the info from the slider, adds em together like $red+$green+$blue, and then makes em a RGB color code which i can then use to change the color of a label, im extremely new to au3 and the helpfile does not tell me howto add numbers or variables together ;) So someone, please help.

You seem to be resisting reading the help file for some reason... o:)

Anyway, I'm a newbie with AutoIT myself, and it was an interesting project for playing with sliders, so I took the example from the help file for GuiCtrlCreateSlider() and modified it. My version sticks with decimal numbers (0xFF = 255):

#include <GuiConstants.au3>

$SlideGui = GUICreate("Slider Test", 356, 130, 100, 200)
GUISetBkColor(0xE0FFFF, $SlideGui)

GUICtrlCreateLabel("RED (0-255)", 10, 10, 70, 20)
$SliderR = GUICtrlCreateSlider(90, 10, 256, 20)
GUICtrlSetLimit($SliderR, 255, 0)
GUICtrlSetData($SliderR, 128)

GUICtrlCreateLabel("Green (0-255)", 10, 40, 70, 20)
$SliderG = GUICtrlCreateSlider(90, 40, 256, 20)
GUICtrlSetLimit($SliderG, 255, 0)
GUICtrlSetData($SliderG, 128)

GUICtrlCreateLabel("Blue (0-255)", 10, 70, 70, 20)
$SliderB = GUICtrlCreateSlider(90, 70, 256, 20)
GUICtrlSetLimit($SliderB, 255, 0)
GUICtrlSetData($SliderB, 128)

$Button1 = GUICtrlCreateButton("Value?", 143, 100, 70, 20)

GUISetState(@SW_SHOW, $SlideGui)

Do
    $Msg = GUIGetMsg($SlideGui)
    If $Msg = $Button1 Then
        $RedVal = GUICtrlRead($SliderR)
        $GreenVal = GUICtrlRead($SliderG)
        $BlueVal = GUICtrlRead($SliderB)
        $Background = ($RedVal * 256 * 256) + ($GreenVal * 256) + ($BlueVal)
        GUISetBkColor($Background, $SlideGui)
        MsgBox(0, "Slider Data", "Slider Data = " & @CRLF & _
                @TAB & "Red  = " & $RedVal & @CRLF & _
                @TAB & "Green = " & $GreenVal & @CRLF & _
                @TAB & "Blue     = " & $BlueVal, 10)
    EndIf
Until $Msg = $Gui_Event_Close

Of course, If you WON'T read the help file you may not be able to run it... :lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

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