Author Topic: [RESOURCE] GetSlidingColorTag  (Read 1006 times)

Code: (Color Tags.cs) [Select]
function GetSlidingColorTag(%value, %list)
{
if((%fields = getFieldCount(%list)) == 0) return "\c6";
for(%i=0;%i<%fields;%i++)
{
if(getWordCount(%field = getField(%list, %i)) != 2) return "\c6";
if(%taken[getWord(%field, 0)]) return "\c6"; %taken[getWord(%field, 0)] = 1;
}
for(%i=0;%i<%fields;%i++)
{
%field = getField(%list, %i);
%val = getWord(%field, 0);
if(%val >= %value && (%val < %maxVal || %maxVal $= ""))
{ %maxVal = %val; %maxColor = getWord(%field, 1); }
if(%val <= %value && (%val > %minVal || %minVal $= ""))
{ %minVal = %val; %minColor = getWord(%field, 1); }
}
if(%minVal == %value || %maxVal $= "") return "<color:"@%minColor@">";
if(%maxVal == %value || %minVal $= "") return "<color:"@%maxColor@">";
%diff = %maxVal - %minVal; %pos = (%value - %minVal) / %diff; %minAmt = 1 - %pos; %maxAmt = %pos;
%minVector = SC_ByteToValue(getSubStr(%minColor, 0, 2)) SPC SC_ByteToValue(getSubStr(%minColor, 2, 2)) SPC SC_ByteToValue(getSubStr(%minColor, 4, 2));
%maxVector = SC_ByteToValue(getSubStr(%maxColor, 0, 2)) SPC SC_ByteToValue(getSubStr(%maxColor, 2, 2)) SPC SC_ByteToValue(getSubStr(%maxColor, 4, 2));
%colVector = vectorAdd(vectorScale(%minVector, %minAmt), vectorScale(%maxVector, %maxAmt));
for(%i=0;%i<3;%i++) %tag = %tag @ SC_ValueToByte(getWord(%colVector, %i));
return "<color:"@%tag@">";
}

function SC_ByteToValue(%byte)
{
for(%i=0;%i<2;%i++)
{
%c = getSubStr(%byte, %i, 1);
switch$(%c)
{
case "A": %c = 10;
case "B": %c = 11;
case "C": %c = 12;
case "D": %c = 13;
case "E": %c = 14;
case "F": %c = 15;
}
%c[%i] = %c;
}
return (%c0*16) + %c1;
}

function SC_ValueToByte(%value)
{
%c0 = mFloor(%value / 16);
%c1 = mFloor(%value) - (%c0 * 16);
for(%i=0;%i<2;%i++)
{
switch(%c[%i])
{
case 10: %c[%i] = "A";
case 11: %c[%i] = "B";
case 12: %c[%i] = "C";
case 13: %c[%i] = "D";
case 14: %c[%i] = "E";
case 15: %c[%i] = "F";
}
}
return %c0@%c1;
}

Usage:

GetSlidingColorTag(%value, %list);
%value - any integer or decimal value.
%list - a list containing all color tags and their respective values, denoted by a space.
    Example: "100.001 FFFFFF   100 00FF00   50 FFFF00   0 FF0000"
Notes: If your list is incorrectly formatted, \c6 is returned by default. If the value is outside the bounds, the closest tag is used.

Brb sliding value knife over my wrists.
No but really what does this do

sooo basically gradients?