Author Topic: Cannot Recognize the Color Black [Solved]  (Read 442 times)

Code: [Select]
//get brick color
%brickRGBA = getColorIDTable(%brick.getColorId());
%r = getWord(%brickRGBA, 0);
%g = getWord(%brickRGBA, 1);
%b = getWord(%brickRGBA, 2);
//echo("brick rgb = " @ %r SPC %g SPC %b);
//echo("brick hsv " @ RGBtoHSV(%r,%g,%b));
%brickH = getWord(RGBtoHSV(%r,%g,%b), 0);

%brickRGB = %r SPC %g SPC %b;
%brickRGB = vectorNormalize(%brickRGB);

//get mat color
%matRGBA = %matColor;
%r = getWord(%matRGBA, 0);
%g = getWord(%matRGBA, 1);
%b = getWord(%matRGBA, 2);
//echo("mat rgb = " @ %r SPC %g SPC %b);
//echo("mat hsv " @ RGBtoHSV(%r,%g,%b));
%matH = getWord(RGBtoHSV(%r,%g,%b), 0);

%matRGB = %r SPC %g SPC %b;
%matRGB = vectorNormalize(%matRGB);

//compare
%hDiff = mAbs(%matH - %brickH);
if(%hDiff > 0.5)
// %hDiff = 1 - %hDiff;
if(%hDiff < 0)
%hDiff = vectorScale(%hDiff,-1);

//echo("hDiff = " @ %hDiff);
bottomPrint(%obj.client,"<font:impact:24><br><br><br><br><color:FFF200><just:right>hDiff = " @ %hDiff SPC "",1);

%obj.isBright=0;
if(%brickRGB $= "1 0 0" || %brickRGB $= "1 0 1" || %brickRGB $= "1 1 1" || %brickRGB $= "0 1 0" || %brickRGB $= "0 1 1" || %brickRGB $= "0 0 1" || %brickRGB $= "0 0 0")
{
echo("isBright");
%obj.isBright=1;
}
isBright only becomes 1 with colors like blue and green, but for black it just doesn't call it.
« Last Edit: July 18, 2013, 03:57:16 AM by tommybricksetti »

Why not just do something like if (%r + %g + %b >= 1), or alternatively if (vectorLen(%r SPC %g SPC %b) >= tolerance)?

Why not just do something like if (%r + %g + %b >= 1), or alternatively if (vectorLen(%r SPC %g SPC %b) >= tolerance)?
Ok but the color in the colorset literally is "0 0 0 1", and the Hex is 000000.

I figured it out. For some reason "0 0 0 1" came out to be "0.59655 0.59655 0.536896" through that method of getting the colorID, so I just added that to the if statement.