Z
zendraw
Guest
Hi,
does some1 know how can i get to display the hex value of a color? Do i have to create such a script myself?
does some1 know how can i get to display the hex value of a color? Do i have to create such a script myself?
///scr_color_value(color);
// B/G/R
var b=colour_get_blue(argument0);
var g=colour_get_green(argument0);
var r=colour_get_red(argument0);
var b10=floor(b/16);
var b1=b-(b10*16);
var g10=floor(g/16);
var g1=g-(g10*16);
var r10=floor(r/16);
var r1=r-(r10*16);
var c;
c[0]='0';
c[1]='1';
c[2]='2';
c[3]='3';
c[4]='4';
c[5]='5';
c[6]='6';
c[7]='7';
c[8]='8';
c[9]='9';
c[10]='A';
c[11]='B';
c[12]='C';
c[13]='D';
c[14]='E';
c[15]='F';
return '$'+string(c[b10])+string(c[b1])+string(c[g10])+string(c[g1])+string(c[r10])+string(c[r1]);
That particular script isn't all that intuitive in my opinion (it sort of works its way backwards and assembles the string from back to front), but here it is in pseudocode:its kinda hard to figure out this script, if u care to explain...
If the input is not 0, we don't yet know what its output is. Otherwise, the output is "00".
We then define a string with all the hex digits in ascending order, such that '0' is in position 0 and 'F' is in position 15. (Note: Every position maps directly to its corresponding hex value.)
Afterwards, we need to split our input number into individual bytes. So to do that, we set up a loop.{
We first pull out the least signifiant byte, by masking the number with $FF.
Then we figure out the high nibble (i.e. the leftmost 4 bits) and we convert that value into a letter by looking it up in our string.
Then we figure out the low nibble (i.e. the rightmost 4 bits) and we also convert it to a letter the same way
Then we insert these two nibbles to the front of our output.
Lastly, we discard the least significant byte of our input and move everything else over by a byte, and we loop until there are no longer any bytes in our input.
}
Then we return the output.
you mean thisYou can set b11 (and the other colors) as b&15. You can set b10 as b>>4.
var b10=b>>4;
var b1=b&15;
var g10=g>>4;
var g1=g&15;
var r10=r>>4;
var r1=r&15;
ok but what does it do? >> shifts a bit, & does?No, && is equivalent to and. & is &.
f is 15. You could use b11&$f if you want.