Author Topic: Getting the darkest color from the colorset  (Read 366 times)

Hi, i've been trying to make a mod that doesn't require the default colorset to work properly, but I don't know how I can get the darkest color from the given color set. I looked in the duplicator's script and found this:
Code: [Select]
function determineBrightestColor()
{
%target = "1 1 1 1";
for(%i = 0; %i < 64; %i++)
{
%colori = getColorIdTable(%i);
%dist = vectorDist(%colori, %target);
if(%dist < %best || %best $= "")
{
%best = %dist;
$Duplicator::HighlightColor = %i;
}
}
}
I cannot understand it. Can someone help?


That's just the part that detects the colour and then sets it to the highlight colour.

Code: [Select]
function determineBrightestColor()
{
%target = "1 1 1 1"; //Goal
for(%i = 0; %i < 64; %i++) //Loop 64 times (Aka through the whole colorset)
{
%colori = getColorIdTable(%i); //Find the values of the 64 colors
%dist = vectorDist(%colori, %target); //Find the distance between the goal and the found values
if(%dist < %best || %best $= "") //If a better color is found...
{
%best = %dist; //... make that color the new best color
$Duplicator::HighlightColor = %i; //Highlight the best color
}
}
}

Tada? This code reads like plain english. Is all code this simple?

Change the "1 1 1 1" to "0 0 0 1" and you should then get the darkest color. I think that the color is in R G B A using the 0 - 1 type thingy.
« Last Edit: January 07, 2011, 01:36:44 AM by Ash »