SRL Archive - Help and Support

Autocoloring?


Sir R. M8gic1an

2008-04-24 01:54:23

hey, i'm quite new to autocoloring and i was wondering if this should, in theory, work:


if not Find[k].AutoColor then
begin
for i:=0 to High(Find[k].Colors) do
begin
ColorToRGB(Find[k].Colors[i], j, l, m)
IncEx(Find[k].RG, (j-l));
IncEx(Find[k].RB, (j-m));
IncEx(Find[k].GB, (l-m));
end;
Find[k].RG := (Find[k].RG/Length(Find[k].Colors))
Find[k].RB := (Find[k].RB/Length(Find[k].Colors))
Find[k].GB := (Find[k].GB/Length(Find[k].Colors))
Find[k].Autocolor := True;
end;

red:=(TestColor mod 256);
green:=((TestColor/256) mod 256);
blue:=((TestColor/256) / 256);
{comparing colors}
if ((green-blue)<=(Find[k].GB+20)) then if ((green-blue)>=(Find[k].GB-20)) then
if ((red-green)>=(Find[k].RG-20)) then if ((red-green)<=(Find[k].RG+20)) then
if ((red-blue)>=(Find[k].RB-20)) then if ((red-blue)<=(Find[k].RB+20)) then


here's the whole procedure if you wanna see how it fits in there:



type
Monster = record
Name: string;
UpText: TStringArray;
Colors: TIntegerArray;
AutoColor: boolean;
RG, RB, GB: integer;
end;
var
Find: Array of Monster;

//Smart Colors By Tarajunky, Custom by Rasta Magician
Function SmartColorsCustom(name:string; UpText:TStringArray; colors:TIntegerArray):boolean;
var
j, k:integer;
b, Found:boolean;
var RMInt, RMx, RMy:integer;
var x,y,TestColor,a,l,m,i,red,green,blue, ClickColor:integer;
var p: array of Tpoint;

begin
if not LoggedIn then exit;
for i:=0 to High(Find) do
begin
if lowercase(name) = Find[i].Name then
begin
b := True;
k := i;
end;
end;

if not b then //we have to add it.
begin
k:=GetArrayLength(Find);
SetArrayLength(Find, k+1);
Find[k].Name:= lowercase(name);
Find[k].UpText := UpText;
Find[k].Colors := colors;
end;

{autocoloring}
if not Find[k].AutoColor then
begin
for i:=0 to High(Find[k].Colors) do
begin
ColorToRGB(Find[k].Colors[i], j, l, m)
IncEx(Find[k].RG, (j-l));
IncEx(Find[k].RB, (j-m));
IncEx(Find[k].GB, (l-m));
end;
Find[k].RG := (Find[k].RG/Length(Find[k].Colors))
Find[k].RB := (Find[k].RB/Length(Find[k].Colors))
Find[k].GB := (Find[k].GB/Length(Find[k].Colors))
Find[k].Autocolor := True;
end;

FFlag(0);
Wait(50);
if RMDebug then writeln('Finding '+name);
l:=GetArrayLength(Find[k].Colors); //Checks known colors first
if l>0 then
begin
for i:= 0 to l-1 do
begin
if RMDebug then writeln('finding color: '+IntToStr(Find[k].Colors[i]));
FindColorsSpiralTolerance(MSCX,MSCY,p,Find[k].Colors[i],MSX1,MSY1,MSX2,MSY2,0);
m:=GetArrayLength(p);
if m>0 then
begin
if m > 30 then exit;
for a:= 0 to m-1 do
begin
if CheckAndClick(p[a].x,p[a].y, Find[k].UpText) then //Moves mouse to position, checks uptext and clicks if correct.
begin
result:=true;
if i>0 then //if the color is not in the first position of the array...
Swap(Find[k].Colors[i], Find[k].Colors[i-1]);
// Swap found color with the one ahead of it in the array
exit; // We found our color, so we exit the function completely.
end;
end;
end;
end;
end;
//We didn't find any known colors, so continue on to the tolerance search
for j:=0 to High(Find[k].Colors) do
begin
if j >= 3 then break; //only wanna look for 3 colors with tol
if RMDebug then writeln('finding color '+IntToStr(Find[k].Colors[j])+' with tol ');
FindColorsSpiralTolerance(MSCX, MSCY, p, Find[k].Colors[j],MSX1,MSY1,MSX2,MSY2,25);
l:=GetArrayLength(p);
if (l>0)and(not l>30) then
begin

for i:= 0 to l-1 do
begin
TestColor:=GetColor(p[i].x,p[i].y); //Additional autocoloring to reduce wrong points. (Optional)
{turning it to RGB}
red:=(TestColor mod 256);
green:=((TestColor/256) mod 256);
blue:=((TestColor/256) / 256);
{comparing colors}
if ((green-blue)<=(Find[k].GB+20)) then if ((green-blue)>=(Find[k].GB-20)) then
if ((red-green)>=(Find[k].RG-20)) then if ((red-green)<=(Find[k].RG+20)) then
if ((red-blue)>=(Find[k].RB-20)) then if ((red-blue)<=(Find[k].RB+20)) then
begin
Wait(20);
ClickColor:=GetColor(p[i].x,p[i].y);

for RMInt:=0 to High(Find[k].Colors) do
begin
if RMInt <> j then
if FindColorSpiralTolerance(RMx, RMy, Find[k].Colors[RMInt],x-5,y-5,x+5,y+5, 20) then
begin
Found:=True;
break;
end;
end;

If Found then
if CheckAndClick(p[a].x,p[a].y, Find[k].UpText) then //Move mouse, check uptext and click
begin
result:=true;
FindColorsSpiralTolerance(x,y,p,ClickColor,MSX1,MSY1,MSX2,MSY2,0);
if GetArrayLength(p)<20 then //Make sure that the color is somewhat rare, and doesn't take up half the screen
begin
a:=GetArrayLength(Find[k].Colors);
for i:= 0 to a-1 do
begin
if ClickColor=Find[k].Colors[i] then //If color is already in the array...
begin
if i>0 then
begin // Move it up one spot in the array search priority
Swap(Find[k].Colors[i], Find[k].Colors[i-1]);
end;
exit;
end;
end;
// if it's not in the array yet, then add it to the end of the array
SetArrayLength(Find[k].Colors,a+1);
Find[k].Colors[a]:=ClickColor;
if RMDebug then Writeln(IntToStr(ClickColor)+' added to '+name+' array');
end;
exit;
end;
end;
end;
end;
end;
end;

thx,
~RM

tarajunky

2008-04-24 12:25:53

What does IncEx do? And why do you compare RG,BG,RB with Length?

It may work, but I can't figure out what those calculations are for.

Sumilion

2008-04-24 13:02:57

Lol @ IncEx … its just the same as Inc but instead of increasing it by 1 it increases it by the parameter in IncEx.

Gu3st...

2008-04-24 14:09:01

Actually Int := Int + 1; is faster than Inc();

JuKKa

2008-04-24 14:22:52

From: Zytex!
Actually Int := Int + 1; is faster than Inc();

I have heard this so many times now. So i did a test… Guess what.. Inc is faster…

program New;

Var
T, I, F: Integer;

Begin
T:= GetSystemTime;
For I:= 0 To 1000000 Do
F := F + 1;
Writeln(IntToStr(getsystemtime-t));
F := 0;
T:= GetSystemTime;
For I:= 0 To 1000000 Do
Inc(F);
Writeln(IntToStr(getsystemtime-t));
End.

out come

3266
3031

Gu3st...

2008-04-24 14:32:15

O rly?

Edit: Yeah rly!

2609
2141

faster789

2008-04-24 14:48:47

:confused: omg can someone just make rev 17 :D with fix of autocolor? thanks, because this is SO confusing :(

tarajunky

2008-04-24 16:15:26

From: Sumilion
Lol @ IncEx … its just the same as Inc but instead of increasing it by 1 it increases it by the parameter in IncEx.


Okay, now I get it. So it goes through all the available colors and averages their rg, gb, and rb values. Then for the color comparison it uses the average +/- 20.

It should work fine, I think.

It's a hard function to generalize, but I think you found a pretty good way to do it.

EvilChicken!

2008-04-24 17:09:34

Ø_ø?! Inc is faster? Offtopic, I know, but Ray said it was twice as slow as int + 1.. It actually is faster! (Tried the script in reversed order also..) Wow. Thanks JuKKa!

Cazax

2008-04-24 17:22:50

red:=(TestColor mod 256);
green:=((TestColor/256) mod 256);
blue:=((TestColor/256) / 256);`
ColorToRGB is faster.

Sir R. M8gic1an

2008-04-26 05:34:11

thanks everyone for your comments, sorry i didn't have time to answer to this cus i've been having problems with my comp.

@ Tara: i'm glad you think so, i haven't had the chance to test it much yet :p
@ Jukka: woohoo!
@ Cazax: this is the way it was originally done, but i might get around to changing it :p btw thx for your tut, it's where i finally grasped autocoloring :)

thx very much everyone!

~RM