Blockland Forums > Modification Help
Color Translation
Ipquarx:
--- Quote from: Nexus on May 02, 2012, 08:46:59 PM ---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.
--- End quote ---
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:
--- Quote from: Ipquarx on May 02, 2012, 11:38:21 PM ---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.
--- End quote ---
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
jes00:
--- Quote from: Nexus on May 03, 2012, 07:57:18 AM ---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
--- End quote ---
So I should use .setColor instead of .color = ?
Port:
--- Quote from: Ipquarx on May 02, 2012, 04:37:31 PM ---No. Absolutely not. That will contain decimal values, which do not work with colours.
--- End quote ---
I used those settings and it worked, creating perfect integers.
--- Quote from: Ipquarx on May 02, 2012, 04:37:31 PM ---Did you think it was just a coincidence that a byte has a maximum value of 255?
--- End quote ---
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
--- Quote from: Ipquarx on May 02, 2012, 04:37:31 PM ---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.
--- End quote ---
This is irrelevant to the post you're replying to.
Ipquarx:
--- Quote from: Port on May 03, 2012, 10:27:41 AM ---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."
--- End quote ---