SRL Archive - OSR Advanced Scripting Tutorials

Autocoloring with RGB,HSL and XYZ!


Cazax

2008-04-15 19:02:39

AUTOCOLORING

With RGB, HSL and XYZ!


First, a short explainment of them:
RGB:
Red
Green
Blue

From: Wikipedia
The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue.




HSL:
Hue
Saturation
Lightness

From: Wikipedia
HSL and HSV are two related representations of points in an RGB color space, which attempt to describe perceptual color relationships more accurately than RGB, while remaining computationally simple. HSL stands for hue, saturation, lightness, while HSV stands for hue, saturation, value.

HSI and HSB are alternative names for these concepts, using intensity and brightness; their definitions are less standardized, but they are typically interpreted as synonymous with HSL.

Both HSL and HSV describe colors as points in a cylinder whose central axis ranges from black at the bottom to white at the top with neutral colors between them, where angle around the axis corresponds to “hue”, distance from the axis corresponds to “saturation”, and distance along the axis corresponds to “lightness”, “value”, or “brightness”.

P.S. We arent going to use HSV.

XYZ:
From: Wikipedia
The human eye has receptors (called cone cells) for short (S), middle (M), and long (L) wavelengths. Thus in principle, three parameters describe a color sensation. The tristimulus values of a color are the amounts of the three primary colors in a three-component additive color model needed to match that test color. The tristimulus values are most often given in the CIE 1931 color space, in which they are denoted X, Y, and Z.

Any specific method for associating tristimulus values with each color is called a color space. CIE XYZ, one of many such spaces, is special because it is based on direct measurements of human visual perception, and serves as the basis from which many other color spaces are defined.





——————————————————————————————————————————————–

Now, we are going to learn how to autocolor with them:

1) Create your function :):
Function MyFirstAutocolor: Integer;

2)Set the variables:
var
R,G,B,TestColor : Integer; // Red, Green and Blue.
H,S,L : Extended; // HSL have decimal numbers
X,Y,Z : Extended; // This one too!
MyColor : Integer; Your Color
ColorsTPA : TPointArray; // We are going to use TPA's
C1 : TIntegerArray; // we are going to use them later
i,C2 : Integer;
I just splited them so you can know why do we need them

3) Now we go through the autocoloring:

MyColor := {put your color here};
Set the color.

FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, {Set a tolerance});  
MSCX,MSCY:We are going to start searching the color from the center of the minimap.

ColorsTPA: The TPA will store the coords of the colors found on the minimap.

MyColor: The color you want to search

MMX1,MMY1,MMX2,MMY2: The coords of the minimap

{set a tolerance}: Set a tolerance to search the color. 60 is good enough, remember, we need high tolerance for a better result.

atm, our function should look like this:
function MyFirstAutocolor: Integer;
var
R,G,B,TestColor : Integer;
H,S,L : Extended;
X,Y,Z : Extended;
MyColor : Integer;
ColorsTPA : TPointArray;
C1 : TIntegerArray;
i,C2 : Integer;
begin
MyColor := 5123364;
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, 60);

Then:

C1 := GetColors(ColorsTPA);
Will get all the colors of the TPA.

C2 := High(C1);
We are going to use for to do so we need this one, this is same as Length(C2) - 1.

The function atm:
function MyFirstAutocolor: Integer;
var
R,G,B,TestColor : Integer;
H,S,L : Extended;
X,Y,Z : Extended;
MyColor,NewColor : Integer;
ColorsTPA : TPointArray;
C1 : TIntegerArray;
i,C2 : Integer;
begin
MyColor := 5123364;
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, 60);
C1 := GetColors(ColorsTPA);
C2 := High(C1);

Now we start the loop:

for i := 0 to C2 do
begin

then a failsafe:

if rs_OnMinimap(ColorsTPA[i].X, Colors[i].Y) then
begin

If the current color(remember, the TPA stored all colors found) is inside the MM then…

TestColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
Will get the color of the current tpa

if SimilarColors(NewColor, MyColor, 50) then
begin
if the colors are similar between the tolerance then…

ColorToRGB(NewColor, R, G, B);
ColorToHSL(NewColor, H, S, L);
ColorToXYZ(NewColor, X, Y, Z);
Will transform the color to RGB,HSL and XYZ.

Now, we need to open another SCAR and then run this:
program New;
var
R,G,B : Integer;
H,S,L,X,Y,Z : Extended;
const
Color = 516564; // set your color
begin
ColorToRGB(Color, R, G, B);
ColorToHSL(Color, H, S, L);
ColorToXYZ(Color, X, Y, Z);
Writeln('R: '+inttostr(R));
Writeln('G: '+inttostr(G));
Writeln('B: '+inttostr(B));
Writeln('');
Writeln('H: '+floattostr(H));
Writeln('S: '+floattostr(S));
Writeln('L: '+floattostr(L));
Writeln('');
Writeln('X: '+floattostr(X));
Writeln('Y: '+floattostr(Y));
Writeln('Z: '+floattostr(Z));
end.
Set the color you want to autocolor at the const "color".
Press run:
You will get the RGB,HSL and XYZ values of your color!

something like this:
// Example:
R: 212
G: 225
B: 7

H: 17,6605507731438
S: 93,9655184745789
L: 45,4901963472366

X: 54,1149417708884
Y: 67,8628162129347
Z: 10,4476862998244

then we continue our function without closing the other SCAR window with the values, but listen now:

a) Get the value of R - G
b) Get Value of R - B
c)Get the value of G - B
d) get the value of S - H
e) get the value of L - H
f) get the value of S - L
g) get the value of X - Y
h) get the value of Y - Z

then we just compare them and if they are between the range then you just get the color:

if InRange(R - G, {your range here}, {your range here}) then
if InRange(R - B, {your range here}, {your range here}) then
if InRange(G - B, {your range here}, {your range here}) then
if InRange(Round(S) - Round(H), {your range here}, {your range here}) then
if InRange(Round(L) - Round(H), {your range here}, {your range here}) then
if InRange(Round(S) - Round(L), {your range here}, {your range here}) then
if InRange(Round(X) - Round(Y), {your range here}, {your range here}) then
if InRange(Round(Y) - Round(Z), {your range here}, {your range here}) then

but wait! the will only work with your color, so we need to add a "tolerance":
if InRange(R - G, {your range here - 20}, {your range here + 20}) then
for RGB use -20 and +20.
for HSL use -15 and +15.
And forum XYZ use -7 and +7.
if your color changes too much you just add a higher range…
now the last part:
if GetColor(ColorsTPA[A].X + 2, ColorsTPA[A].Y + 2) = TestColor then
if GetColor(ColorsTPA[A].X + 1, ColorsTPA[A].Y + 1) = TestColor then
If the pixels near the pixel with the color we found are the same, then we just get the color!:
Writeln('MyColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;

Woot! our function should look something like this:
function MyFirstAutocolor: Integer;
var
R,G,B,TestColor : Integer;
H,S,L : Extended;
X,Y,Z : Extended;
MyColor : Integer;
ColorsTPA : TPointArray;
C1 : TIntegerArray;
i,C2: Integer;
begin
MyColor := 5123364;
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, 60);
C1 := GetColors(ColorsTPA);
C2 := High(C1);
for i := 0 to C2 do
begin
if RS_OnMinimap(ColorsTPA[i].X, ColorsTPA[i].Y) then
begin
TestColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
if SimilarColors(TestColor, 1322555, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -6, 29) then
if InRange(R - B, 25, 55) then
if InRange(G - B, 12, 40) then
if InRange(Round(S) - Round(H), 28, 48) then
if InRange(Round(L) - Round(H), -4, 14) then
if InRange(Round(S) - Round(L), 23, 47) then
if InRange(Round(X) - Round(Y), -8, 9) then
if InRange(Round(Y) - Round(Z), -7, 9) then
if GetColor(ColorsTPA[i].X + 2, ColorsTPA[i].Y + 2) = TestColor then
if GetColor(ColorsTPA[i].X + 1, ColorsTPA[i].Y + 1) = TestColor then
begin
Writeln('MyColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find My Color!');
Result := 0;
end;

P.S if your function failed, try expanding the range.
Thats all!

Da 0wner

2008-04-15 20:16:58

That hurts my brain! I'll try to look at it once i'm smarter :). Well caz why don't you go on msn anymore/much?

Cazax

2008-04-15 20:22:41

Hehe thats why i posted it here, becouse you have to understand TPA's and things. I dont go to MSN becouse im lazy… you will see me once a time :)

Da 0wner

2008-04-15 20:24:40

Well, i understand tpas, but wtf are these hsl, xyz? i no rgb (red blue green, duh) and hsl (hue, saturation, lightness) and whats xyz?

Floor66

2008-04-16 13:11:25

Thank you SO dang much!! This is exactly what i needed! =p

Sumilion

2008-04-16 13:49:27

Oh your going to love the new addition in SRL rev 16 :D

EDIT: ps. nice tut, might be useful to use ACA aswell ? :)

Cazax

2008-04-16 17:07:33

From: Sumilion
Oh your going to love the new addition in SRL rev 16 :D

EDIT: ps. nice tut, might be useful to use ACA aswell ? :)


What addition?
ACA is nicee :D

NiCbaZ

2008-04-16 17:27:16

From: Sumilion
Oh your going to love the new addition in SRL rev 16 :D

EDIT: ps. nice tut, might be useful to use ACA aswell ? :)


ohhh carnt wait for it it sounds nice

nice tut il try and understand it tonight ;)

skilld u

2008-04-16 17:28:10

if InRange(R - G, {your range here}, {your range here}) then

what is my range?

Cazax

2008-04-16 17:31:03

From: skilld u
if InRange(R - G, {your range here}, {your range here}) then

what is my range?


program New;
var
R,G,B : Integer;
H,S,L,X,Y,Z : Extended;
const
Color = 516564; // set your color
begin
ColorToRGB(Color, R, G, B);
ColorToHSL(Color, H, S, L);
ColorToXYZ(Color, X, Y, Z);
Writeln('R: '+inttostr(R));
Writeln('G: '+inttostr(G));
Writeln('B: '+inttostr(B));
Writeln('');
Writeln('H: '+floattostr(H));
Writeln('S: '+floattostr(S));
Writeln('L: '+floattostr(L));
Writeln('');
Writeln('X: '+floattostr(X));
Writeln('Y: '+floattostr(Y));
Writeln('Z: '+floattostr(Z));
end.
There you go.

skilld u

2008-04-16 17:33:27

oh, i use the r value and the g value?

Cazax

2008-04-16 17:37:32

From: skilld u
oh, i use the r value and the g value?

r - g means red - green. Read the tut, the things you are asking is there :p

skilld u

2008-04-16 17:43:54

but there are two things im supposed to input…

Cazax

2008-04-16 17:49:27

From: skilld u
but there are two things im supposed to input…


for example you got 27 as red and 58 as green. 58 - 27 is 31.
31 - 15 is 16. 31 + 15 is 46.
if InRange(r - g, 16, 46) then

skilld u

2008-04-16 17:52:43

oh, thanks. :D

R0b0t1

2008-04-16 17:54:45

I dissected a function for a tut with autocoloring w/ RGB, but you have the whole ShabANNNG.

Sumilion

2008-04-17 08:48:44

From: Cazax
What addition?
ACA is nicee :D


I won't tell too much but it resembles this a lot :)

NiCbaZ

2008-04-17 23:50:35

how long till its out be cool if you could just pit in 2 colors and it autocolors it ;) but that would be the easy way how long till rev#16

lordsaturn

2008-04-17 23:55:55

From: Da 0wner
Well, i understand tpas, but wtf are these hsl, xyz? i no rgb (red blue green, duh) and hsl (hue, saturation, lightness) and whats xyz?



Read the tutorial, Dr. Intelligence.

skilld u

2008-04-18 17:30:19

I got another error with this :(

Line 522: [Error] (15325:15): Type mismatch in script

function FindSandColor: integer; //-15, +15
var
R,G,B : Integer;
H,S,L : Extended;
X,Y,Z : Extended;
Sand,SandColor : Integer;
ColorsTPA : TPointArray;
i,C1,C2 : TIntegerArray;
begin
Sand := 5611431;
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, Sand, MMX1, MMY1, MMX2, MMY2, 55);
C1 := GetColors(ColorsTPA);
ClearSameIntegers(C1);
C2 := High(C1); //this one :O
for i := 0 to C2 do
begin
if rs_OnMinimap(ColorsTPA[i].X, ColorsTPA[i].Y) then
begin
TestColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
if SimilarColors(TestColor, Sand, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -7, 23) then
if InRange(R - B, 67, 97) then
if InRange(G - B, 59, 89) then
if InRange(Round(S) - Round(H), 3, 33) then
if InRange(Round(L) - Round(H), 20, 50) then //
if InRange(Round(S) - Round(L), -32, -2) then //
if InRange(Round(X) - Round(Y), -19, 11) then //
if InRange(Round(Y) - Round(Z), 5, 35) then
if GetColor(TPA[i].X + 2, TPA[i].Y + 2) = TestColor then
if GetColor(TPA[i].X + 1, TPA[i].Y + 1) = TestColor then
begin
WriteLn('MyColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find My Color!');
Result := 0;
end;

Cazax

2008-04-18 17:32:19

From: skilld u
I got another error with this :(

Line 522: [Error] (15325:15): Type mismatch in script

function FindSandColor: integer; //-15, +15
var
R,G,B : Integer;
H,S,L : Extended;
X,Y,Z : Extended;
Sand,SandColor : Integer;
ColorsTPA : TPointArray;
i,C1,C2 : TIntegerArray;
begin
Sand := 5611431;
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, Sand, MMX1, MMY1, MMX2, MMY2, 55);
C1 := GetColors(ColorsTPA);
ClearSameIntegers(C1);
C2 := High(C1); //this one :O
for i := 0 to C2 do
begin
if rs_OnMinimap(ColorsTPA[i].X, ColorsTPA[i].Y) then
begin
TestColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
if SimilarColors(TestColor, Sand, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -7, 23) then
if InRange(R - B, 67, 97) then
if InRange(G - B, 59, 89) then
if InRange(Round(S) - Round(H), 3, 33) then
if InRange(Round(L) - Round(H), 20, 50) then //
if InRange(Round(S) - Round(L), -32, -2) then //
if InRange(Round(X) - Round(Y), -19, 11) then //
if InRange(Round(Y) - Round(Z), 5, 35) then
if GetColor(TPA[i].X + 2, TPA[i].Y + 2) = TestColor then
if GetColor(TPA[i].X + 1, TPA[i].Y + 1) = TestColor then
begin
WriteLn('MyColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find My Color!');
Result := 0;
end;


Replace that line for Length(C1) - 1

skilld u

2008-04-18 17:44:13

Changed to C2 := Length(C1) - 1; and tried this, but still get type mismatch.

function FindSandColor: integer;
var
R,G,B : Integer;
H,S,L : Extended;
X,Y,Z : Extended;
Sand,SandColor : Integer;
ColorsTPA : TPointArray;
i,C1,C2 : TIntegerArray;
begin
Sand := 5611431;
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, Sand, MMX1, MMY1, MMX2, MMY2, 55);
C1 := GetColors(ColorsTPA);
ClearSameIntegers(C1);
for i := 0 to Length(C1) - 1 do
begin
if rs_OnMinimap(ColorsTPA[i].X, ColorsTPA[i].Y) then
begin
TestColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
if SimilarColors(TestColor, Sand, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -7, 23) then
if InRange(R - B, 67, 97) then
if InRange(G - B, 59, 89) then
if InRange(Round(S) - Round(H), 3, 33) then
if InRange(Round(L) - Round(H), 20, 50) then
if InRange(Round(S) - Round(L), -32, -2) then
if InRange(Round(X) - Round(Y), -19, 11) then
if InRange(Round(Y) - Round(Z), 5, 35) then
if GetColor(TPA[i].X + 2, TPA[i].Y + 2) = TestColor then
if GetColor(TPA[i].X + 1, TPA[i].Y + 1) = TestColor then
begin
WriteLn('MyColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find My Color!');
Result := 0;
end;

Cazax

2008-04-18 17:50:22

You declare i as TIntegerArray, i should be Integer

Shuttleu

2008-04-19 16:30:46

well i took notice from the post above and fixed it but now it wont find the color
this is the script
function FindBankColor: Integer;
var
R,G,B : Integer; // Red, Blue and Red we are going to use them
H,S,L : Extended; // HSL have decimal numbers
X,Y,Z : Extended; // This one too!
MyColor,TestColor : Integer; // The color we are going to 'AutoColor' and the new color is the new color :S
ColorsTPA : TPointArray; // We are going to use TPA's
C1,C2 : TIntegerArray; // we are going to use them later
i : Integer;
begin
MyColor := 904417;
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, 60);
C1 := GetColors(ColorsTPA);
ClearSameIntegers(C1);
for i := 0 to Length(C1) - 1 do
begin
if RS_OnMinimap(ColorsTPA[i].X, ColorsTPA[i].Y) then
begin
TestColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
if SimilarColors(TestColor, MyColor, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, 16, 46) then
if InRange(R - B, 197, 227) then
if InRange(G - B, -36, -6) then
if InRange(Round(S) - Round(H), 59, 89) then
if InRange(Round(L) - Round(H), 17, 47) then
if InRange(Round(S) - Round(L), 27, 57) then
if InRange(Round(X) - Round(Y), -21, 9) then
if InRange(Round(Y) - Round(Z), 35, 65) then
if GetColor(ColorsTPA[i].X + 2, ColorsTPA[i].Y + 2) = TestColor then
if GetColor(ColorsTPA[i].X + 1, ColorsTPA[i].Y + 1) = TestColor then
begin
Writeln('MyColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find My Color!');
Result := 0;
end;

if someone could make it for me using this color then i can adapt it from that
color : 904417 (its the bank symbol color)

~shut

Cazax

2008-04-19 19:18:07

Dont check for the pixels near the color:
if GetColor(ColorsTPA[i].X + 2, ColorsTPA[i].Y + 2) = TestColor then
if GetColor(ColorsTPA[i].X + 1, ColorsTPA[i].Y + 1) = TestColor

FreakyMonkey

2008-04-20 13:09:49

excellent tutorial, but hey could this possibly be used to check if one is logged out? and to look for specific colors in certain areas?

Cazax

2008-04-20 13:14:32

From: freakymonkey
excellent tutorial, but hey could this possibly be used to check if one is logged out? and to look for specific colors in certain areas?


just change this:
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, 60);
to the area you want to look.

FreakyMonkey

2008-04-20 17:46:27

alright sweet! =)

Sir R. M8gic1an

2008-04-21 04:35:40

great tut, answered a few questions i had about AutoColoring!

~RM

q3ick

2008-04-24 19:37:36

Thanks man, cant wait to put this into my script :p

Camaro'

2008-04-26 11:00:28

Good tutorial, im testing out my autocolor.. It didnt work lol..

I was reading over the replys and saw this..
From: Cazax
for example you got 27 as red and 58 as green. 58 - 27 is 31.
31 - 15 is 16. 31 + 15 is 46.
if InRange(r - g, 16, 46) then


Where do you get the number 15?

Everything else in that post i get fine.

EDIT AGAIN:
IS 15 the tolerance??? cause if it is i get it now..

faster789

2008-04-26 11:59:04

R: 95
G: 96
B: 88

H: 18.75
S: 4.34782579541206
L: 36.0784322023392

X: 10.6636375115794
Y: 11.5032188520144
Z: 10.8908279770015

Umm this is what I got now what do i do with this?

Cazax

2008-04-26 12:01:06

From: cnr sport
Good tutorial, im testing out my autocolor.. It didnt work lol..

I was reading over the replys and saw this..


Where do you get the number 15?

Everything else in that post i get fine.

EDIT AGAIN:
IS 15 the tolerance??? cause if it is i get it now..

15 Is a sort of tolerance, if the color changes too much, use 20, 25, etc…


From: faster789
R: 95
G: 96
B: 88

H: 18.75
S: 4.34782579541206
L: 36.0784322023392

X: 10.6636375115794
Y: 11.5032188520144
Z: 10.8908279770015

Umm this is what I got now what do i do with this?

Uhmmm…Read the tut?

faster789

2008-04-26 12:08:57

Lol i did, but what I mean is when you did yours you didnt have decimals in it so I'm asking if its right. -_-//

Cazax

2008-04-26 12:10:05

From: faster789
Lol i did, but what I mean is when you did yours you didnt have decimals in it so I'm asking if its right. -_-//


Yes its right, just round it :p

Camaro'

2008-04-26 12:10:56

From: Cazax
15 Is a sort of tolerance, if the color changes too much, use 20, 25, etc…



Uhmmm…Read the tut?


i have a 25 "sort of " tolerance cause im trying to autocolor the color of a oak tree on the mini map..

function MMoakcolor: Integer;
var
R,G,B : Integer; // Red, Blue and Red we are going to use them
H,S,L : Extended; // HSL have decimal numbers
X,Y,Z : Extended; // This one too!
MyColor,NewColor : Integer; // The color we are going to 'AutoColor' and the new color is the new color :S
ColorsTPA : TPointArray; // We are going to use TPA's
C1,C2 : TIntegerArray; // we are going to use them later
i : Integer;
begin
MyColor := 18195;
FindColorsSpiralTolerance(MMCX, MMCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, 60);
C1 := GetColors(ColorsTPA);
ClearSameIntegers(C1);
for i := 0 to Length(C1) - 1 do
begin
if rs_OnMinimap(ColorsTPA[i].X, ColorsTPA[i].Y) then
begin
NewColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
if SimilarColors(NewColor, MyColor, 50) then
begin
ColorToRGB(NewColor, R, G, B);
ColorToHSL(NewColor, H, S, L);
ColorToXYZ(NewColor, X, Y, Z);
if InRange(R - G, -77, -27) then
if InRange(R - B, -6, 44) then
if InRange(G - B, 56, 106) then
if InRange(Round(S) - Round(H), -96, -46) then
if InRange(Round(L) - Round(H), -40, 10) then
if InRange(Round(S) - Round(L), 61, 111) then
if InRange(Round(X) - Round(Y), -17, 13) then
if InRange(Round(Y) - Round(Z), -11, 19) then
if GetColor(colorsTPA[i].X + 2, colorsTPA[i].Y + 2) = NewColor then
if GetColor(colorsTPA[i].X + 1, colorsTPA[i].Y + 1) = NewColor then
begin
Writeln('Color = '+Inttostr(NewColor));
Result := NewColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find the Color!');
Result := 0;
end;

IT WILL NEVER WORK! .. Please tell me why.. and please tell me possible fixes..? Im gonna rep you now for helping me

Cazax

2008-04-26 12:12:49

From: cnr sport
i have a 25 "sort of " tolerance cause im trying to autocolor the color of a oak tree on the mini map..

function MMoakcolor: Integer;
var
R,G,B : Integer; // Red, Blue and Red we are going to use them
H,S,L : Extended; // HSL have decimal numbers
X,Y,Z : Extended; // This one too!
MyColor,NewColor : Integer; // The color we are going to 'AutoColor' and the new color is the new color :S
ColorsTPA : TPointArray; // We are going to use TPA's
C1,C2 : TIntegerArray; // we are going to use them later
i : Integer;
begin
MyColor := 18195;
FindColorsSpiralTolerance(MMCX, MMCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, 60);
C1 := GetColors(ColorsTPA);
for i := 0 to Length(C1) - 1 do
begin
if rs_OnMinimap(ColorsTPA[i].X, ColorsTPA[i].Y) then
begin
NewColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
if SimilarColors(NewColor, MyColor, 50) then
begin
ColorToRGB(NewColor, R, G, B);
ColorToHSL(NewColor, H, S, L);
ColorToXYZ(NewColor, X, Y, Z);
if InRange(R - G, -77, -27) then
if InRange(R - B, -6, 44) then
if InRange(G - B, 56, 106) then
if InRange(Round(S) - Round(H), -96, -46) then
if InRange(Round(L) - Round(H), -40, 10) then
if InRange(Round(S) - Round(L), 61, 111) then
if InRange(Round(X) - Round(Y), -17, 13) then
if InRange(Round(Y) - Round(Z), -11, 19) then
if GetColor(colorsTPA[i].X + 2, colorsTPA[i].Y + 2) = NewColor then
if GetColor(colorsTPA[i].X + 1, colorsTPA[i].Y + 1) = NewColor then
begin
Writeln('Color = '+Inttostr(NewColor));
Result := NewColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find the Color!');
Result := 0;
end;

IT WILL NEVER WORK! .. Please tell me why.. and please tell me possible fixes..? Im gonna rep you now for helping me

Delete this:
ClearSameIntegers(C1);
And, are you sure those numbers are negative?

faster789

2008-04-26 12:14:45

you might want to show how you changed your second program and implemented it to the myfirstautocolor funcction…because apparently you didnt use the same range of the second program to the autocolor function, because they both are differnt..

Camaro'

2008-04-26 12:16:30

From: Cazax
Delete this:
ClearSameIntegers(C1);
And, are you sure those numbers are negative?


I think they are, but why would i delete that.. Im gonna try it now..

Edit: Doesnt work either..

Cazax

2008-04-26 12:16:40

From: faster789
you might want to show how you changed your second program and implemented it to the myfirstautocolor funcction…because apparently you didnt use the same range of the second program to the autocolor function, because they both are differnt..

they arent the same becouse they are different examples.

Camaro'

2008-04-26 12:20:40

From: Cazax
they arent the same becouse they are different examples.


Do you have any ideas of how i can fix my problem?

Cazax

2008-04-26 12:28:59

Function FindMMOakTree : Integer;
var
H,S,L,X,Y,Z : Extended;
R,G,B,P,A,TestColor,xx,xy : Integer;
TPA : TPointArray;
begin
if Not(LoggedIn) then Exit;
xx:= MMCX;
xy := MMCY;
FindColorsSpiralTolerance(xx, xy, TPA, 1068078, MMX1, MMY1, MMX2, MMY2, 60)
P := High(TPA);
for A := 0 to P do
begin
if RS_OnMinimap(TPA[A].X, TPA[A].Y) then
begin
TestColor := GetColor(TPA[A].X, TPA[A].Y);
if SimilarColors(TestColor, 1068078, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -50, -10) then
if InRange(R - B, 10, 54) then
if InRange(G - B, 32, 99) then
if InRange(Round(S) - Round(H), 22, 73) then
if InRange(Round(L) - Round(H), -17, 2) then
if InRange(Round(S) - Round(L), 30, 75) then
if InRange(Round(X) - Round(Y), -9, 5) then
if InRange(Round(Y) - Round(Z), 2, 8) then
if GetColor(TPA[A].X + 2, TPA[A].Y + 2) = TestColor then
if GetColor(TPA[A].X + 1, TPA[A].Y + 1) = TestColor then
begin
Writeln('MMOakColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find MMOakColor!');
Result := 0;
end;
Test it

Camaro'

2008-04-26 12:35:32

From: Cazax
Function FindMMOakTree : Integer;
var
H,S,L,X,Y,Z : Extended;
R,G,B,P,A,TestColor,xx,xy : Integer;
TPA : TPointArray;
begin
if Not(LoggedIn) then Exit;
xx:= MMCX;
xy := MMCY;
FindColorsSpiralTolerance(xx, xy, TPA, 1068078, MMX1, MMY1, MMX2, MMY2, 60)
P := High(TPA);
for A := 0 to P do
begin
if RS_OnMinimap(TPA[A].X, TPA[A].Y) then
begin
TestColor := GetColor(TPA[A].X, TPA[A].Y);
if SimilarColors(TestColor, 1068078, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -50, -10) then
if InRange(R - B, 10, 54) then
if InRange(G - B, 32, 99) then
if InRange(Round(S) - Round(H), 22, 73) then
if InRange(Round(L) - Round(H), -17, 2) then
if InRange(Round(S) - Round(L), 30, 75) then
if InRange(Round(X) - Round(Y), -9, 5) then
if InRange(Round(Y) - Round(Z), 2, 8) then
if GetColor(TPA[A].X + 2, TPA[A].Y + 2) = TestColor then
if GetColor(TPA[A].X + 1, TPA[A].Y + 1) = TestColor then
begin
Writeln('MMOakColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find MMOakColor!');
Result := 0;
end;
Test it



WOW- you own for just making me the proc.. Im testing now.. will edit this post

Didnt find the color.. The first time.. now it always does.. thanks! reped u but it always finds the wrong color..

vikrant60

2008-04-27 02:29:54

So…. ummmm do i call the function in the script and it will find color and idk what to do next rofl.

HyperSecret

2008-04-30 02:42:11

if you dont know the basics of colors and what autocoloring is used for then go to simpler tuts first

vikrant60

2008-05-02 06:38:33

From: HyperSecret
if you dont know the basics of colors and what autocoloring is used for then go to simpler tuts first


Worked it out :D

Pure1993

2008-05-02 17:20:21

Hey Cazax, I promised I would go through your tut again, and guess what, here I am :D
I am not quite done (well, reading it over for the third time, but this time I will try to really concentrate ;)), but I noticed one thing:
 ClearSameInteger(C1);
should be
 ClearSameIntegers(C1);
just a hint for those of you who get the (i think it was) type mismatch error.
I will edit this post when I am done and I understood it :)

EDIT: Well, finished an (mostly) understood (still having problems getting the correct ranges, but I guess that's just a matter of time and practice till I get good enough with it).
Now I only have two questions left:
1.) Why the heck didn't i get this the first and second time I read this?!?!?!!?
2.) Why the heck isn't this stickied? I think it deserves it! Autocoloring is a huge part of rs cheat writing scripts, and everyone should understand what the are using…
Thanks for an awesome guide, rep++ for you. :)

PS: Now the function which you made for me looks official:
{*******************************************************************************
function HouseColor: Integer;
By: Cazax;
Modified by: Pure1993 (Only ironing out the few type mismatches ;D )
Description: Detects the color of the house in the Lumbridge graveyard in which
the ghost appears in the Restless Ghost quest.
*******************************************************************************}

function HouseColor: Integer;
var
X,Y,Z, H, S, L : Extended;
R,G,B,P,A,TestColor,xx,xy : Integer;
TPA : TPointArray;
begin
if Not(LoggedIn) then Exit;
xx:= MMCX;
xy := MMCY;
FindColorsSpiralTolerance(xx, xy, TPA, 3227710, MMX1, MMY1, MMX2, MMY2, 60)
P := High(TPA);
for A := 0 to P do
begin
if RS_OnMinimap(TPA[A].X, TPA[A].Y) then
begin
TestColor := GetColor(TPA[A].X, TPA[A].Y);
if SimilarColors(TestColor, 4739921, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -22, 18) then
if InRange(R - B, -11, 29) then
if InRange(G - B, -9, 31) then
if InRange(Round(X) - Round(Y), -7, 7) then
if InRange(Round(Y) - Round(Z), -6, 8) then
if GetColor(TPA[A].X + 2, TPA[A].Y + 2) = TestColor then
if GetColor(TPA[A].X + 1, TPA[A].Y + 1) = TestColor then
begin
Writeln('HouseColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find Color!');
Result := 0;
end;
Now it looks like it came straight from the srl library ;).

Cazax

2008-05-02 21:18:15

From: Pure1993
Hey Cazax, I promised I would go through your tut again, and guess what, here I am :D
I am not quite done (well, reading it over for the third time, but this time I will try to really concentrate ;)), but I noticed one thing:
 ClearSameInteger(C1);
should be
 ClearSameIntegers(C1);
just a hint for those of you who get the (i think it was) type mismatch error.
I will edit this post when I am done and I understood it :)

EDIT: Well, finished an (mostly) understood (still having problems getting the correct ranges, but I guess that's just a matter of time and practice till I get good enough with it).
Now I only have two questions left:
1.) Why the heck didn't i get this the first and second time I read this?!?!?!!?
2.) Why the heck isn't this stickied? I think it deserves it! Autocoloring is a huge part of rs cheat writing scripts, and everyone should understand what the are using…
Thanks for an awesome guide, rep++ for you. :)

PS: Now the function which you made for me looks official:
{*******************************************************************************
function HouseColor: Integer;
By: Cazax;
Modified by: Pure1993 (Only ironing out the few type mismatches ;D )
Description: Detects the color of the house in the Lumbridge graveyard in which
the ghost appears in the Restless Ghost quest.
*******************************************************************************}

function HouseColor: Integer;
var
X,Y,Z, H, S, L : Extended;
R,G,B,P,A,TestColor,xx,xy : Integer;
TPA : TPointArray;
begin
if Not(LoggedIn) then Exit;
xx:= MMCX;
xy := MMCY;
FindColorsSpiralTolerance(xx, xy, TPA, 3227710, MMX1, MMY1, MMX2, MMY2, 60)
P := High(TPA);
for A := 0 to P do
begin
if RS_OnMinimap(TPA[A].X, TPA[A].Y) then
begin
TestColor := GetColor(TPA[A].X, TPA[A].Y);
if SimilarColors(TestColor, 4739921, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -22, 18) then
if InRange(R - B, -11, 29) then
if InRange(G - B, -9, 31) then
if InRange(Round(X) - Round(Y), -7, 7) then
if InRange(Round(Y) - Round(Z), -6, 8) then
if GetColor(TPA[A].X + 2, TPA[A].Y + 2) = TestColor then
if GetColor(TPA[A].X + 1, TPA[A].Y + 1) = TestColor then
begin
Writeln('HouseColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find Color!');
Result := 0;
end;
Now it looks like it came straight from the srl library ;).

Thank you :) i forgot say something ill edit the tut…

King of the Nites

2008-05-02 22:50:46

Dang, thanks for this it really helped me out with my script. You get some rep++.

Pure1993

2008-05-03 12:13:14

Np Cazax, but you still didn't change the thing i mean, you missed the "s" in ClearSameIntegers. ;)

ShowerThoughts

2008-05-03 13:14:50

Nice, i get everything but what to fill in by inrange I don't get :(

Cazax

2008-05-03 20:45:28

From: Hermpie
Nice, i get everything but what to fill in by inrange I don't get :(

Uhm ill explain it more. Editing it atm.
From: Pure1993
Np Cazax, but you still didn't change the thing i mean, you missed the "s" in ClearSameIntegers. ;)

Uhhh…

EvilChicken!

2008-05-04 07:00:58

From: Cazax
for example you got 27 as red and 58 as green. 58 - 27 is 31.
31 - 15 is 16. 31 + 15 is 46.
if InRange(r - g, 16, 46) then


Shit. :S Shouldn't it be G - R then?

Ooh. I get it now. You're written something wrong in your tut.
You say R - G, but you did G - R. >_<

NiCbaZ

2008-05-12 06:21:41

greeeat!!!!!!!!!!!!

Function AutoBankerColor: Integer;

var
R,G,B : Integer;
H,S,L : Extended;
X,Y,Z : Extended;
MyColor,TestColor : Integer;
ColorsTPA : TPointArray;
C1: TIntegerArray;
i : Integer;
begin
MyColor := 5123368
FindColorsSpiralTolerance(MSCX, MSCY, ColorsTPA, MyColor, MMX1, MMY1, MMX2, MMY2, 60);
C1 := GetColors(ColorsTPA);
ClearSameIntegers(C1);
for i := 0 to Length(C1) - 1 do
begin
if rs_OnMinimap(ColorsTPA[i].X, ColorsTPA[i].Y) then
begin
TestColor := GetColor(ColorsTPA[i].X, ColorsTPA[i].Y);
if SimilarColors(TestColor,5123368, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -13, 27) then
if InRange(R - B, -12, 28) then
if InRange(G - B, -19, 21) then
if InRange(Round(S) - Round(H), 24, 54) then
if InRange(Round(L) - Round(H), 25, 55) then
if InRange(Round(S) - Round(L), -53, -23) then
if InRange(Round(X) - Round(Y), -7 , 7) then
if InRange(Round(Y) - Round(Z), -8 , 6) then
if GetColor(ColorsTPA[i].X + 2, ColorsTPA[i].Y + 2) = TestColor then
if GetColor(ColorsTPA[i].X + 1, ColorsTPA[i].Y + 1) = TestColor then
begin
Writeln('MyColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find My Color!');
Result := 0;
end;

tested & worked :p

itSchRis917

2008-05-13 01:29:31

Hmmm.. mine doesnt work. I've already increased the tolerance to +30 and -30 on RGB, +20 and -20 on HSL, and +10 and -10 on XYZ… See anything wrong with my procedure?



const
ExtendedDebug = True;

var
i, c, b, a, cx, cy : integer;
ColorList: Integer;
RangePoints:TPointArray;
RangePoint:TPoint;
Range2DSplit : T2DPointArray;
Furnace: Integer;
C1 : TIntegerArray;

function AutoColorRange: Integer;
var
R, G, B: Integer;
H, S, L: Extended;
X, Y, Z: Extended;
begin
if not LoggedIn then exit;
Furnace := 7963267;
cx := MSCX;
cy := MSCY;
for C := 0 to 10 do
begin
FindColorsSpiralTolerance(cx, cy, RangePoints, Furnace, MSX1, MSY1, MSX2, MSY2, C);
if(Length(RangePoints) - 1 >= 10)then
Break;
end;

Range2DSplit := SplitTPA(RangePoints, 4);
for i := 0 to Length(Range2DSplit) - 1 do
begin
if not LoggedIn then exit;
SortATPAFrom(Range2DSplit, IntToPoint(MSCX, MSCY));
RangePoint:= MiddleTPA(Range2DSplit[i]);
if (ExtendedDebug) then
begin
Writeln('Found '+IntToStr(GetArrayLength(RangePoints))+' possible points.');
Writeln('Split into '+IntToStr(Length(Range2DSplit) - 1)+ ' T2DPointArrays.');
end;

C1 := GetColors(RangePoints);
for a := 0 to Length(C1) - 1 do
begin

begin
cx := RangePoint.x;
cy := RangePoint.y;
ColorList := GetColor(RangePoints[a].X, RangePoints[a].Y);
//if SimilarColors(ColorList, Furnace, 50) then
begin

ColorToRGB(ColorList, R, G, B);
ColorToHSL(ColorList, H, S, L);
ColorToXYZ(ColorList, X, Y, Z);
if InRange(R - G, 95, 155) then
if InRange(R - B, 109, 169) then
if InRange(G - B, -16, 44)then
if InRange(Round(S) - Round(H), -46, -16) then
if InRange(Round(L) - Round(H), -61, -31) then
if InRange(Round(S) - Round(L), -6, 34) then
if InRange(Round(X) - Round(Y), -10, 10) then
if InRange(Round(Y) - Round(Z), -15, 5 ) then
if GetColor(RangePoints[a].X + 2, RangePoints[a].Y + 2) = ColorList then
if GetColor(RangePoints[a].X + 1, RangePoints[a].Y + 1) = ColorList then
begin
Writeln('MyColor = '+Inttostr(ColorList));
Result := ColorList;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find My Color!');
Result := 0;
end;
end;

Drakan

2008-05-17 18:09:23

make them 1 big example so we can see how you take those numbers and make them into ranges, and the final result of those numbers. Would love it a lot.

Cazax

2008-05-17 18:36:25

From: The[Cheese]
make them 1 big example so we can see how you take those numbers and make them into ranges, and the final result of those numbers. Would love it a lot.


Read the whole tut, somewhere it says:
Get the value of R - G…
These are the ranges.

itSchRis917

2008-06-05 22:16:51

Defenite rep+ for this. Helped me a lot!

Jackrawl

2008-06-06 18:40:00

Your last example doesn't compile.

Waddo

2008-06-06 18:53:06

R,G,B : Integer; // Red, Blue and Red we are going to use them

you mean red green and blue?

hmm good thread easy to understand what iveread so far but the colors hurt my eyes =]

Cazax

2008-06-06 19:10:21

From: waddo
R,G,B : Integer; // Red, Blue and Red we are going to use them

you mean red green and blue?

hmm good thread easy to understand what iveread so far but the colors hurt my eyes =]

Oops, yes i meant red, green and blue.

From: JackLKrawl
Your last example doesn't compile.
you are SRL member, you can make it compile :)

From: itschris917
Defenite rep+ for this. Helped me a lot!

Np

Jackrawl

2008-06-06 19:28:18

From: Cazax
Oops, yes i meant red, green and blue.

you are SRL member, you can make it compile :)


Np


Or we could have a correct last example that uses and summarizes the tutorial as it so claims :)

itSchRis917

2008-06-06 20:57:09

Yeah, it did confuse me a little bit since like you used 2 different functions throughout the tutorial.. And the fact that the ending one didnt compile was.. eh

Jackrawl

2008-06-06 21:42:52

I wish I could get rep'd for non-compiling material.

Cazax

2008-06-06 22:33:11

Ok, now it compiles…

EDIT: Corrected the tut.

Jackrawl

2008-06-06 23:29:14

From: Cazax
Ok, now it compiles…

EDIT: Corrected the tut.


Cool, now it's time for +rep. xD

Actually, another thought.
RGB, HSL, XYZ - whatever, it doesn't matter whether or not that there is a scientifical format, just so long as there is a formula. We aren't recreating colors, we're just checking with a few different tolerances, taking the first one matching and giving an exact color.

Xtensity

2008-09-03 16:46:22

You still did not provide an example. I have no idea what this is used for still there for its harder for me to grasp the concept of it -.-

Cazax

2008-09-03 17:19:53

From: Xtensity
You still did not provide an example. I have no idea what this is used for still there for its harder for me to grasp the concept of it -.-

An example? read the last function, it was a working example. Now this tutorial just explains how do they work, because with reflection and other new siht you can do the walking part.