pwnaz0r
08-18-2007, 02:56 AM
RGB.scar - The Tutorial
http://wlmwebstatus.servepics.com/status/pwnaz0r@hotmail.com-16.png
This tutorial is only for the explanation of things in RGB.scar. The thread can be found Here - http://www.villavu.com/forum/showthread.php?t=15494
Current Functions
CreateRGB(red, green, blue : integer) : RGB;
CompareColorsRGB(color1, color2 : integer; reportit : boolean) : array of integer;
CompareColorArrayRGB(colors : array of integer; reportIt : boolean) : array of integer;
AutoColorMM(var ResultColor : integer; Color : integer; Colors : array of integer);
FindClosestRGB(R, G, B, x1, y1, x2, y2 : Integer) : Integer;
FindRGBTolerance(var x,y, RsltColor : integer; Red, Green, Blue, RTol, GTol, BTol, x1, y1, x2, y2 : integer) : boolean;
-----------------------------------------------------------------------------------------------------------
Function CreateRGB(red, green, blue : integer) : RGB;
{************************************************* ******************************
function CreateRGB(Red, Green, Blue : integer) : RGB;
By: Pwnaz0r
Description: Creates an RGB Component.
************************************************** *****************************}
function CreateRGB(color : integer) : RGB;
begin
ColorToRGB(Color, result.red, result.green, result.blue);
end;
Red : Red Integer;
Green : Green Integer;
Blue : Blue Integer;
Uses : Creating RGB's. RGB's are the main variable in RGB.scar. Therefor it is essential.
-----------------------------------------------------------------------------------------------------------
function CompareColorsRGB(color1, color2 : integer; reportit : boolean) : array of integer;
{************************************************* ******************************
function CompareColorsRGB(Color1, Color2: integer; ReportIt : boolean) : array of integer;
By: Pwnaz0r
Description: Gets Max R, G, and B Differences.
************************************************** *****************************}
function CompareColorsRGB(Color1, Color2: integer; ReportIt : boolean) : array of integer;
var
K : integer;
begin
result := CompareColorsRGBEx(Color1,Color2);
If ReportIt Then
begin
AddToReport('(' + IntToStr(Color1) + ', ' + IntToStr(Color2) + ')');
AddToReport('---------------');
For k := 0 to 2 do
begin
case K of
0 : AddToReport('Max Red : ' + IntToStr(result[k]));
1 : AddToReport('Max Green : ' + IntToStr(result[k]));
2 : AddToReport('Max Blue : ' + IntToStr(result[k]));
end;
end;
AddToReport('---------------');
AddToReport(' ');
end;
end;
Color1 : The First Color To Compare ( Regular Color )
Color2 : The Second Color To Compare ( Regular Color )
ReportIt : Report the Colors In The Report Box ( More User Friendly ).
Uses : Will Get the Max R, G, and B differences. Used for auto-coloring.
-----------------------------------------------------------------------------------------------------------
CompareColorArrayRGB(colors : array of integer; reportIt : boolean) : array of integer;
{************************************************* ******************************
function CompareColorArrayRGB(Colors : array of integer; ReportIt : boolean) : array of integer;
By: Pwnaz0r
Description: Gets the Max R, G, and B differences in an array.
************************************************** *****************************}
function CompareColorArrayRGB(Colors : array of integer; ReportIt : boolean) : array of integer;
var
TmpR, TmpG, TmpB, Al, K : integer;
tmpArray : array of integer;
begin
Al := (GetArrayLength(colors) - 2);
For K := 0 to Al do
begin
If not SameValue(Colors[K],Colors[K + 1])then
begin
SetArrayLength(tmpArray,0);//Clearing of Vars
tmpArray := CompareColorsRGB(Colors[K],Colors[K + 1],False);
If TmpR = 0 then
begin
TmpR := tmpArray[0];
end else
begin
tmpR := Max(tmpR,tmpArray[0]);
end;
If TmpG = 0 then
begin
TmpG := tmpArray[1];
end else
begin
tmpG := Max(tmpG,tmpArray[1]);
end;
If TmpB = 0 then
begin
TmpB := tmpArray[2];
end else
begin
tmpB := Max(tmpB,tmpArray[2]);
end;
end;
end;
SetArrayLength(result,3);
result[0] := tmpR;
result[1] := tmpG;
result[2] := tmpB;
If ReportIt Then
begin
AddToReport('---------------');
AddToReport('Max Red : ' + IntToStr(result[0]));
AddToReport('Max Green : ' + IntToStr(result[1]));
AddToReport('Max Blue : ' + IntToStr(result[2]));
AddToReport('---------------');
AddToReport(' ');
end;
end;
colors : The array of colors to compare.
ReportIt : Report the Colors In The Report Box ( More User Friendly ).
Uses : Will Get The Max R,G, and B differences for the whole array.
-----------------------------------------------------------------------------------------------------------
Procedure AutoColorMM(var ResultColor : integer; Color : integer; Colors : array of integer);
{************************************************* ******************************
procedure AutoColorMM(var ResultColor : integer; Color : integer; Colors : array of integer);
By: Pwnaz0r
Description: Auto-Colors a MiniMap Color with Max tolerances found in 'Colors'.
************************************************** *****************************}
procedure AutoColorMM(var ResultColor : integer; Color : integer; Colors : array of integer);
var
tmpTArray : array of TPoint;
tmpNum, x1x, y1y : integer;
tmpArray2, tmpArray3 : array of integer;
begin
Flag;
FindColorsSpiralTolerance(x1x , y1y, tmpTArray, Color, 563, -4, 722, 169, 40);
tmpArray2 := CompareColorArrayRGB(Colors,False);
For tmpNum := 0 to (GetArrayLength(tmpTArray) - 1) do
begin
tmpArray3 := CompareColorsRGB(Color,GetColor(tmpTArray[tmpNum].X,tmpTArray[tmpNum].Y),False);
x1x := tmpTArray[tmpNum].X;
y1y := tmpTArray[tmpNum].Y;
If tmpArray3[0] <= tmpArray2[0] then
If tmpArray3[1] <= tmpArray2[1] then
If tmpArray3[2] <= tmpArray2[2] then
begin
ResultColor := GetColor(x1x,y1y);
MMouse(x1x,y1y,0,0);
Exit;
end;
end;
Writeln('Color Not Found');
ResultColor := 0;
end;
ResultColor : The Color Variable to return the new color as.
Color : Main Color.
colors : The array of colors to compare.
Uses : AutoColoring any Color on the map. All you do is Insert your Color Array into the spot ( you should have about 4 or 5 ) and it will find the map. Use the first Color in your array as the "Main Color" or Color.
-----------------------------------------------------------------------------------------------------------
function FindClosestRGB(R, G, B, x1, y1, x2, y2 : Integer) : Integer;
{************************************************* ******************************
function FindClosestRGB(R, G, B, x1, y1, x2, y2 : Integer) : Integer;
By: Pwnaz0r
Description: Finds the Closest Color with Tolerance.
************************************************** *****************************}
function FindClosestRGB(R, G, B, x1, y1, x2, y2 : Integer) : Integer;
var
I, H, K, L, tmpInt, ClosestInt : Integer;
tmpTArray : Array of TPoint;
tmpIntArray, rsltArray : Array of Integer;
tmpRGBArray : array of RGB;
begin
Flag;
For I := 0 to 80 do
begin
FindColorsSpiralTolerance(x, y, tmpTArray, (RGBToColor(R,G,B)), x1, y1, x2, y2, I);
If GetArrayLength(tmpTArray) = 0 then
begin
end else
begin
SetArrayLength(tmpIntArray,0);
For H := 0 to GetArrayLength(tmpTArray) - 1 do
begin
SetArrayLength(tmpIntArray,GetArrayLength(tmpIntAr ray) + 1);
tmpIntArray[H] := GetColor(tmpTArray[H].X, tmpTArray[H].Y);
end;
SetArrayLength(rsltArray,0);
for K := 0 to GetArrayLength(tmpIntArray) - 1 do
begin
SetArrayLength(rsltArray,GetArrayLength(rsltArray) + 1);
tmpRGBArray[k] := CreateRGB(tmpIntArray[K]);
tmpRGBArray[K].X := tmpTArray[K].X;
tmpRGBArray[K].Y := tmpTArray[K].Y;
rsltArray[K] := (tmpRGBArray[K].red + tmpRGBArray[K].green + tmpRGBArray[K].blue);
end;
ClosestInt := MinArray(tmpInt, rsltArray);
result := GetColor(tmpRGBArray[tmpInt].X,tmpRGBArray[tmpInt].Y);
end;
end;
end;
R : The Red Value
G : The Green Value
B : The Blue Value
X1,Y1,X2,Y2 : The Coordinates
-----------------------------------------------------------------------------------------------------------
function FindRGBTolerance(var x,y, RsltColor : integer; Red, Green, Blue, RTol, GTol, BTol, x1, y1, x2, y2 : integer) : boolean;
function FindRGBTolerance(var x,y, RsltColor : integer; Red, Green, Blue, RTol, GTol, BTol, x1, y1, x2, y2 : integer) : boolean;
var
I, tmpNum, K : integer;
begin
For K := Y1 to Y2 do
begin
For I := X1 to X2 do
begin
tmpNum := ConvertRGB('red',GetColor(I,K));
If (Max(tmpNum,Red) - Min(tmpNum,Red)) <= Rtol then
begin
tmpNum := ConvertRGB('green',GetColor(I,K));
If (Max(tmpNum,Green) - Min(tmpNum,Green)) <= Gtol then
begin
tmpNum := ConvertRGB('blue',GetColor(I,K));
If (Max(tmpNum,Blue) - Min(tmpNum,Blue)) <= Btol then
begin
Result := true;
RsltColor := GetColor(I,K);
x := I;
y := K;
Exit;
End;
end;
end;
end;
end;
Result := False;
end;
x,y : variables to store where the color is.
RsltColor : variabe to store the color found
Red, Green, Blue: RGB Values
RTol, GTol, BTol : Max Tolerance Values;
X1,Y1,X2,Y2 : Coordinates to search within
Uses : Finding Colors With Tolerances More Accurately.
http://wlmwebstatus.servepics.com/status/pwnaz0r@hotmail.com-16.png
This tutorial is only for the explanation of things in RGB.scar. The thread can be found Here - http://www.villavu.com/forum/showthread.php?t=15494
Current Functions
CreateRGB(red, green, blue : integer) : RGB;
CompareColorsRGB(color1, color2 : integer; reportit : boolean) : array of integer;
CompareColorArrayRGB(colors : array of integer; reportIt : boolean) : array of integer;
AutoColorMM(var ResultColor : integer; Color : integer; Colors : array of integer);
FindClosestRGB(R, G, B, x1, y1, x2, y2 : Integer) : Integer;
FindRGBTolerance(var x,y, RsltColor : integer; Red, Green, Blue, RTol, GTol, BTol, x1, y1, x2, y2 : integer) : boolean;
-----------------------------------------------------------------------------------------------------------
Function CreateRGB(red, green, blue : integer) : RGB;
{************************************************* ******************************
function CreateRGB(Red, Green, Blue : integer) : RGB;
By: Pwnaz0r
Description: Creates an RGB Component.
************************************************** *****************************}
function CreateRGB(color : integer) : RGB;
begin
ColorToRGB(Color, result.red, result.green, result.blue);
end;
Red : Red Integer;
Green : Green Integer;
Blue : Blue Integer;
Uses : Creating RGB's. RGB's are the main variable in RGB.scar. Therefor it is essential.
-----------------------------------------------------------------------------------------------------------
function CompareColorsRGB(color1, color2 : integer; reportit : boolean) : array of integer;
{************************************************* ******************************
function CompareColorsRGB(Color1, Color2: integer; ReportIt : boolean) : array of integer;
By: Pwnaz0r
Description: Gets Max R, G, and B Differences.
************************************************** *****************************}
function CompareColorsRGB(Color1, Color2: integer; ReportIt : boolean) : array of integer;
var
K : integer;
begin
result := CompareColorsRGBEx(Color1,Color2);
If ReportIt Then
begin
AddToReport('(' + IntToStr(Color1) + ', ' + IntToStr(Color2) + ')');
AddToReport('---------------');
For k := 0 to 2 do
begin
case K of
0 : AddToReport('Max Red : ' + IntToStr(result[k]));
1 : AddToReport('Max Green : ' + IntToStr(result[k]));
2 : AddToReport('Max Blue : ' + IntToStr(result[k]));
end;
end;
AddToReport('---------------');
AddToReport(' ');
end;
end;
Color1 : The First Color To Compare ( Regular Color )
Color2 : The Second Color To Compare ( Regular Color )
ReportIt : Report the Colors In The Report Box ( More User Friendly ).
Uses : Will Get the Max R, G, and B differences. Used for auto-coloring.
-----------------------------------------------------------------------------------------------------------
CompareColorArrayRGB(colors : array of integer; reportIt : boolean) : array of integer;
{************************************************* ******************************
function CompareColorArrayRGB(Colors : array of integer; ReportIt : boolean) : array of integer;
By: Pwnaz0r
Description: Gets the Max R, G, and B differences in an array.
************************************************** *****************************}
function CompareColorArrayRGB(Colors : array of integer; ReportIt : boolean) : array of integer;
var
TmpR, TmpG, TmpB, Al, K : integer;
tmpArray : array of integer;
begin
Al := (GetArrayLength(colors) - 2);
For K := 0 to Al do
begin
If not SameValue(Colors[K],Colors[K + 1])then
begin
SetArrayLength(tmpArray,0);//Clearing of Vars
tmpArray := CompareColorsRGB(Colors[K],Colors[K + 1],False);
If TmpR = 0 then
begin
TmpR := tmpArray[0];
end else
begin
tmpR := Max(tmpR,tmpArray[0]);
end;
If TmpG = 0 then
begin
TmpG := tmpArray[1];
end else
begin
tmpG := Max(tmpG,tmpArray[1]);
end;
If TmpB = 0 then
begin
TmpB := tmpArray[2];
end else
begin
tmpB := Max(tmpB,tmpArray[2]);
end;
end;
end;
SetArrayLength(result,3);
result[0] := tmpR;
result[1] := tmpG;
result[2] := tmpB;
If ReportIt Then
begin
AddToReport('---------------');
AddToReport('Max Red : ' + IntToStr(result[0]));
AddToReport('Max Green : ' + IntToStr(result[1]));
AddToReport('Max Blue : ' + IntToStr(result[2]));
AddToReport('---------------');
AddToReport(' ');
end;
end;
colors : The array of colors to compare.
ReportIt : Report the Colors In The Report Box ( More User Friendly ).
Uses : Will Get The Max R,G, and B differences for the whole array.
-----------------------------------------------------------------------------------------------------------
Procedure AutoColorMM(var ResultColor : integer; Color : integer; Colors : array of integer);
{************************************************* ******************************
procedure AutoColorMM(var ResultColor : integer; Color : integer; Colors : array of integer);
By: Pwnaz0r
Description: Auto-Colors a MiniMap Color with Max tolerances found in 'Colors'.
************************************************** *****************************}
procedure AutoColorMM(var ResultColor : integer; Color : integer; Colors : array of integer);
var
tmpTArray : array of TPoint;
tmpNum, x1x, y1y : integer;
tmpArray2, tmpArray3 : array of integer;
begin
Flag;
FindColorsSpiralTolerance(x1x , y1y, tmpTArray, Color, 563, -4, 722, 169, 40);
tmpArray2 := CompareColorArrayRGB(Colors,False);
For tmpNum := 0 to (GetArrayLength(tmpTArray) - 1) do
begin
tmpArray3 := CompareColorsRGB(Color,GetColor(tmpTArray[tmpNum].X,tmpTArray[tmpNum].Y),False);
x1x := tmpTArray[tmpNum].X;
y1y := tmpTArray[tmpNum].Y;
If tmpArray3[0] <= tmpArray2[0] then
If tmpArray3[1] <= tmpArray2[1] then
If tmpArray3[2] <= tmpArray2[2] then
begin
ResultColor := GetColor(x1x,y1y);
MMouse(x1x,y1y,0,0);
Exit;
end;
end;
Writeln('Color Not Found');
ResultColor := 0;
end;
ResultColor : The Color Variable to return the new color as.
Color : Main Color.
colors : The array of colors to compare.
Uses : AutoColoring any Color on the map. All you do is Insert your Color Array into the spot ( you should have about 4 or 5 ) and it will find the map. Use the first Color in your array as the "Main Color" or Color.
-----------------------------------------------------------------------------------------------------------
function FindClosestRGB(R, G, B, x1, y1, x2, y2 : Integer) : Integer;
{************************************************* ******************************
function FindClosestRGB(R, G, B, x1, y1, x2, y2 : Integer) : Integer;
By: Pwnaz0r
Description: Finds the Closest Color with Tolerance.
************************************************** *****************************}
function FindClosestRGB(R, G, B, x1, y1, x2, y2 : Integer) : Integer;
var
I, H, K, L, tmpInt, ClosestInt : Integer;
tmpTArray : Array of TPoint;
tmpIntArray, rsltArray : Array of Integer;
tmpRGBArray : array of RGB;
begin
Flag;
For I := 0 to 80 do
begin
FindColorsSpiralTolerance(x, y, tmpTArray, (RGBToColor(R,G,B)), x1, y1, x2, y2, I);
If GetArrayLength(tmpTArray) = 0 then
begin
end else
begin
SetArrayLength(tmpIntArray,0);
For H := 0 to GetArrayLength(tmpTArray) - 1 do
begin
SetArrayLength(tmpIntArray,GetArrayLength(tmpIntAr ray) + 1);
tmpIntArray[H] := GetColor(tmpTArray[H].X, tmpTArray[H].Y);
end;
SetArrayLength(rsltArray,0);
for K := 0 to GetArrayLength(tmpIntArray) - 1 do
begin
SetArrayLength(rsltArray,GetArrayLength(rsltArray) + 1);
tmpRGBArray[k] := CreateRGB(tmpIntArray[K]);
tmpRGBArray[K].X := tmpTArray[K].X;
tmpRGBArray[K].Y := tmpTArray[K].Y;
rsltArray[K] := (tmpRGBArray[K].red + tmpRGBArray[K].green + tmpRGBArray[K].blue);
end;
ClosestInt := MinArray(tmpInt, rsltArray);
result := GetColor(tmpRGBArray[tmpInt].X,tmpRGBArray[tmpInt].Y);
end;
end;
end;
R : The Red Value
G : The Green Value
B : The Blue Value
X1,Y1,X2,Y2 : The Coordinates
-----------------------------------------------------------------------------------------------------------
function FindRGBTolerance(var x,y, RsltColor : integer; Red, Green, Blue, RTol, GTol, BTol, x1, y1, x2, y2 : integer) : boolean;
function FindRGBTolerance(var x,y, RsltColor : integer; Red, Green, Blue, RTol, GTol, BTol, x1, y1, x2, y2 : integer) : boolean;
var
I, tmpNum, K : integer;
begin
For K := Y1 to Y2 do
begin
For I := X1 to X2 do
begin
tmpNum := ConvertRGB('red',GetColor(I,K));
If (Max(tmpNum,Red) - Min(tmpNum,Red)) <= Rtol then
begin
tmpNum := ConvertRGB('green',GetColor(I,K));
If (Max(tmpNum,Green) - Min(tmpNum,Green)) <= Gtol then
begin
tmpNum := ConvertRGB('blue',GetColor(I,K));
If (Max(tmpNum,Blue) - Min(tmpNum,Blue)) <= Btol then
begin
Result := true;
RsltColor := GetColor(I,K);
x := I;
y := K;
Exit;
End;
end;
end;
end;
end;
Result := False;
end;
x,y : variables to store where the color is.
RsltColor : variabe to store the color found
Red, Green, Blue: RGB Values
RTol, GTol, BTol : Max Tolerance Values;
X1,Y1,X2,Y2 : Coordinates to search within
Uses : Finding Colors With Tolerances More Accurately.