SCAR Code:
program New;
function similarity(a,b:integer): integer;
var
h1,h2,s1,s2,l1,l2: extended;
begin
colortohsl(a, h1, s1, l1);
colortohsl(b, h2, s2, l2)
result := ceil(maxe(maxe(abs(h1 - h2) / 0.2, abs(s1 - s2) / 0.2), abs(l1 - l2)));
end;
function SimilarColors2(col1, col2, tol: Integer): Boolean;
var
R1,G1,B1,R2,G2,B2 : Integer;
ExtA1,ExtB1,ExtC1,ExtA2,ExtB2,ExtC2,Sum,Dnx,Dny : extended;
begin
ColorToRGB(Col1,R1,G1,B1);
ColorToRGB(Col2,R2,G2,B2);
RGBToHSL(R1,g1,b1,ExtA1,ExtB1,ExtC1);
RGBToHSL(R2,g2,b2,ExtA2,ExtB2,ExtC2);
Result := ((abs(ExtA1 - ExtA2) <= (0.2 * tol)) and (abs(ExtB2-ExtB1) <= (0.2 * tol)) and (abs(ExtC2-ExtC1) <= Tol));
end;
var
i, cl1, cl2: integer;
begin
cl1 := random(clWhite);
cl2 := random(clWhite);
writeln(inttostr(similarity(cl1, cl2)));
for i := 0 to 10000 do
if similarcolors2(cl1, cl2, i) then
begin
writeln(inttostr(i));
break;
end;
colortolerancespeed(2);
setcolorspeed2modifiers(0.2, 0.2);
for i := 0 to 10000 do
if similarcolors(cl1, cl2, i) then
begin
writeln(inttostr(i));
break;
end;
end.
Run it, and check the debug output: first 2 numbers are my function, 3rd one SCAR's. If all 3 match: run it another few times, and you'll see that sometimes they differ.