Author Topic: Official Coding Resources Thread (02/29/2016)  (Read 51130 times)

I'll add it in a few minutes.

This is one of port's resources, I'm quite fond of it and I don't think port remembered about it / doesn't care for it / maybe didn't want to post about it.
If it's the 3rd one port, I'll remove it. This takes Blockland's RGB Decimals and converts to HEX.
Code: [Select]
function hidToChr(%n) //Allows for 255ToHex
{
return getSubStr("0123456789ABCDEF",%n,1);
}
function rgbToHex(%rgb)
{
return s255ToHex(255*getWord(%rgb,0)) @ s255ToHex(255*getWord(%rgb,1)) @ s255ToHex(255*getWord(%rgb,2));
}
function s255ToHex(%d)
{
%r = mFloor(%d/16);
%d -= %r * 16;
return hidToChr(%r) @ hidToChr(%d);
}

Did you see this?

I don't get what it is people like about putting the opening brace on it's own line, it just looks weird IMO.
I was actually the one who started this, then Z0W0 added some stuff, then everyone forgot about it.
It's actually for TextMate, but ST2 is mostly compatible with TM bundles.
Same note as above, but only tested with ST2. Also, it's Nullable (not dc4f).
http://forum.blockland.us/index.php?topic=215304.0

This is one of port's resources, I'm quite fond of it and I don't think port remembered about it / doesn't care for it / maybe didn't want to post about it.
If it's the 3rd one port, I'll remove it. This takes Blockland's RGB Decimals and converts to HEX.

Wow, that's old. What are you using it for by the way?
Here, I wrote a newer version just now that also lets you go the other way:

Code: [Select]
function rgbToHex( %rgb )
{
%r = _compToHex( 255 * getWord( %rgb, 0 ) );
%g = _compToHex( 255 * getWord( %rgb, 0 ) );
%b = _compToHex( 255 * getWord( %rgb, 0 ) );

return %r @ %g @ %b;
}

function hexToRgb( %rgb )
{
%r = _hexToComp( getSubStr( %rgb, 0, 2 ) ) / 255;
%g = _hexToComp( getSubStr( %rgb, 2, 2 ) ) / 255;
%b = _hexToComp( getSubStr( %rgb, 4, 2 ) ) / 255;

return %r SPC %g SPC %b;
}

function _compToHex( %comp )
{
%left = mFloor( %comp / 16 );
%comp = mFloor( %comp - %left * 16 );

%left = getSubStr( "0123456789ABCDEF", %left, 1 );
%comp = getSubStr( "0123456789ABCDEF", %comp, 1 );

return %left @ %comp;
}

function _hexToComp( %hex )
{
%left = getSubStr( %hex, 0 );
%comp = getSubStr( %hex, 1 );

%left = striPos( "0123456789ABCDEF", %left );
%comp = striPos( "0123456789ABCDEF", %comp );

if ( %left < 0 || %comp < 0 )
{
return 0;
}

return %left * 16 + %comp;
}

holy crap it got pinned lol

Wow, that's old. What are you using it for by the way?
Here, I wrote a newer version just now that also lets you go the other way:

Code: [Select]
function rgbToHex( %rgb )
{
%r = _compToHex( 255 * getWord( %rgb, 0 ) );
%g = _compToHex( 255 * getWord( %rgb, 0 ) );
%b = _compToHex( 255 * getWord( %rgb, 0 ) );

return %r @ %g @ %b;
}

function hexToRgb( %rgb )
{
%r = _hexToComp( getSubStr( %rgb, 0, 2 ) ) / 255;
%g = _hexToComp( getSubStr( %rgb, 2, 2 ) ) / 255;
%b = _hexToComp( getSubStr( %rgb, 4, 2 ) ) / 255;

return %r SPC %g SPC %b;
}

function _compToHex( %comp )
{
%left = mFloor( %comp / 16 );
%comp = mFloor( %comp - %left * 16 );

%left = getSubStr( "0123456789ABCDEF", %left, 1 );
%comp = getSubStr( "0123456789ABCDEF", %comp, 1 );

return %left @ %comp;
}

function _hexToComp( %hex )
{
%left = getSubStr( %hex, 0 );
%comp = getSubStr( %hex, 1 );

%left = striPos( "0123456789ABCDEF", %left );
%comp = striPos( "0123456789ABCDEF", %comp );

if ( %left < 0 || %comp < 0 )
{
return 0;
}

return %left * 16 + %comp;
}
Oh sweet! I needed to convert 1 .45 0 colors into hex for uses in a cmd UI, which I remembered your Zeig UI had functionality for, so I used the converter from that.

This is one of port's resources, I'm quite fond of it and I don't think port remembered about it / doesn't care for it / maybe didn't want to post about it.
If it's the 3rd one port, I'll remove it. This takes Blockland's RGB Decimals and converts to HEX.
Code: [Select]
snip

If you write any resources in this thread, they will be ignored.

Link it to a pastebin or a topic.


http://pastebin.com/c6cCXAz0
This is still port's (Updated edition)
I already made a base converter, you can easily make a rgb to hex converter out of it, so I don't see how this is needed.

I already made a base converter, you can easily make a rgb to hex converter out of it, so I don't see how this is needed.
It's just preference. This has much more shorter code, and I've been using it for a while.

I'm sure this has been covered and I feel like a dumbass, but I want to make simple commands that make things happen or be said in chat, and I would also love to have a server in which I can type a command to bring up simple things and essentially I just need to know how to command..

I got the code completed (looked at tut) how do I save it?

Next resource from me: how to use the search bar effectively.

Next resource from me: how to use the search bar effectively.
I searched.