Author Topic: Color Translation  (Read 2285 times)

Thank you this works perfectly.
So I'm to use this method to translate it from the GuiSwatchCtrl to the GuiSlider controls? If so which one do I use?

What exactly are you trying to do?  I still strongly feel that you might be wasting your time with working with 0-255 numbers at all unless your specific goal requires you to convert.  Otherwise you can have the slider go from 0 to 1 and keep everything 0-1 as well.

guiswatchcontrol.setcolor(); uses 0-1 input NOT 0-255

What exactly are you trying to do?  I still strongly feel that you might be wasting your time with working with 0-255 numbers at all unless your specific goal requires you to convert.  Otherwise you can have the slider go from 0 to 1 and keep everything 0-1 as well.

guiswatchcontrol.setcolor(); uses 0-1 input NOT 0-255
I am having sliders that change the color of a swatch control (which you are wrong, it uses 0-255) and for the slider I am now using 0.000000 to 1.000000 for.

I am having sliders that change the color of a swatch control (which you are wrong, it uses 0-255) and for the slider I am now using 0.000000 to 1.000000 for.

Ok, then set the range from 0 to 255 on the slider control, set snap to false, and use mfloor() to get rid of decimals.
« Last Edit: May 02, 2012, 04:39:58 PM by elm »

what

set ticks to 0 and snap to false
No. Absolutely not. That will contain decimal values, which do not work with colours.
Did you think it was just a coincidence that a byte has a maximum value of 255? and that each 2 hex characters have a maximum value of 255, and that 3 sets of those make up a rgb colour?

No. It's like that for a reason. A colour is 3 values from 0 and 255, each one of those values taking up ONE byte. Decimal numbers take up MANY more bytes than 1.
You need to round down.

So I'm to use this method to translate it from the GuiSwatchCtrl to the GuiSlider controls? If so which one do I use?
You don't have to convert. I'm just saying that if you wanted to convert it to hex, that's what you can use.

guiswatchcontrol.setcolor(); uses 0-1 input NOT 0-255
You're probably thinking of bitmap controls.

You know jes, I can just make an example of this for you if you want, using only answers obtained from this topic.

I am having sliders that change the color of a swatch control (which you are wrong, it uses 0-255) and for the slider I am now using 0.000000 to 1.000000 for.

Also, it may or may not be useful to note (depending on what you are exactly doing) that gui controls only need to be 0-255 when you are creating the gui object.  After that, you can do gui.setcolor("r g b a"); and those use floats from 0 to 1

You can just have the slider control go 0 to 1 also and you never need to convert to the 0-255 version.

I have written serveral extensive mods that revolve around this.  I know what I am talking about.  You try to use .setcolor() with 0-255 inputs and you will be a sad panda.

I have written serveral extensive mods that revolve around this.  I know what I am talking about.  You try to use .setcolor() with 0-255 inputs and you will be a sad panda.
Nexus, all the .setcolor does is multiply by 255, round down, then do .color = blah.
If you do 0.5 and 0.5001 you will see no difference whatsoever, and if you look at the color value for the swatch control, it will be 255 based.

Nexus, all the .setcolor does is multiply by 255, round down, then do .color = blah.
If you do 0.5 and 0.5001 you will see no difference whatsoever, and if you look at the color value for the swatch control, it will be 255 based.

I am aware of this.  But that does not change the fact that it uses 0-1 input and there is no reason to take the extra step.

Plus I generally avoid using guiobj.var = " "; because it seems to not always be reliable, such as with .text
Using a built in function to set a value is much more reliable
« Last Edit: May 03, 2012, 08:06:20 AM by Nexus »

I am aware of this.  But that does not change the fact that it uses 0-1 input and there is no reason to take the extra step.

Plus I generally avoid using guiobj.var = " "; because it seems to not always be reliable, such as with .text
Using a built in function to set a value is much more reliable
So I should use .setColor instead of .color = ?

No. Absolutely not. That will contain decimal values, which do not work with colours.

I used those settings and it worked, creating perfect integers.

Did you think it was just a coincidence that a byte has a maximum value of 255?

How could it be? It's a simple mathematical calculation. A byte consists of eight bits. A bit is in base 2, thus the maximum value is the secondary value (usually represented as 1): 11111111
If we distance this a bit more, we can display the values beneath and do a simple calculation.

1     1    1    1    1   1   1   1
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255


and that each 2 hex characters have a maximum value of 255, and that 3 sets of those make up a rgb colour?

No. It's like that for a reason. A colour is 3 values from 0 and 255, each one of those values taking up ONE byte. Decimal numbers take up MANY more bytes than 1.

This is irrelevant to the post you're replying to.
« Last Edit: May 03, 2012, 10:29:34 AM by Port »

I used those settings and it worked, creating perfect integers. Exactly. Using decimals takes up resources that torque could be using for more important things.

How could it be? It's a simple mathematical calculation. A byte consists of eight bits. A bit is in base 2, thus the maximum value is the secondary value (usually represented as 1): 11111111
If we distance this a bit more, we can display the values beneath and do a simple calculation.

1     1    1    1    1   1   1   1
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
Thats what I just said.

This is irrelevant to the post you're replying to. It was a continued explination, hence the "and."

Exactly. Using decimals takes up resources that torque could be using for more important things

Integers can't store decimals. You're talking about floating point values.

Thats what I just said.

Err, what?

It was a continued explination, hence the "and."

I wouldn't be posting in this topic if I didn't know what binary, bytes and RGB was.

So I should use .setColor instead of .color = ?

That is my recommendation, yes
.setcolor() has some built in error handling, and it is generally good to use a built in function to set a variable if provided.