Blockland Forums > Modification Help

Color Translation

Pages: << < (2/6) > >>

Port:


--- Quote from: jes00 on April 30, 2012, 07:26:56 AM ---range = "0.200000 1.000000"

--- End quote ---

your problem

jes00:


--- Quote from: Port on April 30, 2012, 07:28:23 AM ---your problem

--- End quote ---
Oops, I mean't range = "0.000000 255.000000"

I keep typing in the wrong things today : /

EDIT: I tried translating the colors from a color set to GuiSwatchCtrl but but multiplying them by 255 but it didn't work.

phflack:

try multiplying and then using floor on that value

Nexus:

Here is one that I wrote to convert it the other way around


--- Code: ---function tmbi_coltohex(%col)
{
for(%a=0; %a<3; %a++)
%b[%a] = tmbi_dectohex(getword(%col, %a)*255);
return %b0 @ %b1 @ %b2;
}

function tmbi_dectohex(%x)
{
%a0 = mfloor(%x/16);
%a1 = mfloor(%x - 16*%a0);

for(%i=0; %i<2; %i++)
{
if(%a[%i] == 10)
%a[%i] = "a";
else if(%a[%i] == 11)
%a[%i] = "b";
else if(%a[%i] == 12)
%a[%i] = "c";
else if(%a[%i] == 13)
%a[%i] = "d";
else if(%a[%i] == 14)
%a[%i] = "e";
else if(%a[%i] == 15)
%a[%i] = "f";
}
return %a0 @ %a1;
}
--- End code ---

It should be super straightforwardd to reverse it.

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.

Slicks555:


--- Code: ---function colToHex(%col) {
  for(%word = 0; %word < 3; %word++)
      %return = %return @ toHex(getWord(%col, %word)*255);
  return %return;
}

function toHex(%d) {
  %r = %d % 16;
  if (%d-%r == 0)
    %result = toChar(%r);
  else
    %result = toHex( (%d-%r)/16 ) @ toChar(%r);
  return %result;
}
 
function toChar(%n) {
  %alpha = "0123456789ABCDEF";
  return getSubStr(%alpha,%n,1);
}
--- End code ---

That's what I'd use.

Pages: << < (2/6) > >>

Go to full version