SRL Archive - SRL Archives

Autocoloring non-static colors...


Cazax

2009-01-11 20:49:15

Function AutoColorIt(Color : TColor): Integer;
Var
TPA, TPA2 : TPointArray;
I, J, bestCol, maxTol : Integer;
Cols : TIntegerArray;
Begin
SetLength(TPA2, 0);
FindColorsTolerance(TPA, Color, MMX1, MMY1, MMX2, MMY2, 25);
For I := 0 To High(TPA) Do
If rs_OnMinimap(TPA[I].X, TPA[I].Y) Then
Begin
SetArrayLength(TPA2, Length(TPA2) + 1);
TPA2[High(TPA2)] := TPA[I];
End;
Cols := GetColors(TPA2);
maxTol := 50;
For I := 0 To High(Cols) Do
If SimilarColors(Cols[I], Color, maxTol) And (Cols[I] <> bestCol) Then
Begin
bestCol := Cols[I];
For J := 0 To 442 Do
If SimilarColors(bestCol, Color, J) Then
Begin
maxTol := J;
Break;
End;
End;
If maxTol > 30 Then
Exit;
Result := bestCol;
Writeln('Max Tolerance Found = ' + IntToStr(maxTol));
Writeln('Color = ' + IntToStr(Color));
End;
Autocolors non-static colors. Checks for the best tolerance and color. No need for tolerance or other specifications, just insert the color.
Now, some pics:
WaterColor:

Trees(in MM):

RoadColor:

:)

Shady?

2009-01-11 23:23:41

Yeah latin power. I'd use this at my Junior Members competition but it would be against the rules. I'll give it a try later when i need to make some walking, and post a nice feedback of how it worked.

mormonman

2009-01-11 23:41:32

wow… completely missed this, nice cazax! i might use this on my next project… success rate?

ian.

2009-01-11 23:42:34

I'm confused on how to use =X

mormonman

2009-01-11 23:45:44


i := AutoColorIt(color);
if RadialRoadWalk(i, start, end, radius, xmod, ymod) then blah;

ian.

2009-01-11 23:53:42

???

still confused

Sandstorm

2009-01-12 04:55:47

if RadialRoadWalk(AutoColorIt(Color), start, end, radius, xmod, ymod) then blah;

I don't understand it either. If it's static, you don't need to autocolor it? :/.

~Sandstorm

Cazax

2009-01-12 07:43:25

From: Sandstorm
if RadialRoadWalk(AutoColorIt(Color), start, end, radius, xmod, ymod) then blah;

I don't understand it either. If it's static, you don't need to autocolor it? :/.

~Sandstorm

You need to autocolor because it will change… by autocoloring static colors i meant you just use a color without a tolerance.

Sandstorm

2009-01-12 08:00:36

Oh xD. I get it now. Sorry!

~Sandstorm

massive630

2009-01-12 18:59:29

Im testing it now in my current project.

works way better than what i was using before. You're gunna get credit when i release.

senrath

2009-01-12 21:28:20

I'm a bit confused about this line:
For J := 0 To 442 Do
Why 442? That would result in any color matching, no matter how far apart they are.

mormonman

2009-01-12 22:48:36

isn't 442 the maxtol for anything…? or is that 255?

Cazax

2009-01-13 07:12:37

442 is the max tolerance in CTS 1.

Naum

2009-01-13 11:21:44

Good Work, just a hint. Couldn't you change the TColor to an Integer???

Illkillutill

2009-01-13 18:29:47

He uses the TInteger because he is using it in a tpa, if it was just an integer, he would not be able to run through the tpa looking for the similar colors

i think? lol.

massive630

2009-01-16 16:09:48

From: Cazax



Trees(in MM):

RoadColor:



quick question: what program did you use to find the matching colors in your pictures?

Cazax

2009-01-16 16:11:23

From: massive630
quick question: what program did you use to find the matching colors in your pictures?

I use DebugTPA by Wizzup:
Function DebugTPA(Points: TPointArray; BmpName: String): Boolean;

Var
Width, Height, ClientBMP, I: Integer;
xs, ys, xe, ye: Integer;

Begin
Try
Begin
xe := xs xor xs;
ye := ys xor ys;
xs := 1 shl 20;
ys := 1 shl 20;

For I := 0 To High(Points) Do
Begin
xs := Min(xs, Points[i].X);
ys := Min(ys, Points[i].Y);

xe := Max(xe, Points[i].X);
ye := Max(ye, Points[i].Y);
End;

Width := xe - xs;
Height := ye - ys;

DisplayDebugImgWindow(0, 0);
DisplayDebugImgWindow(Width, Height);
ClientBMP := BitmapFromString(Width, Height, '');

CopyClientToBitmap(ClientBMP, xs, ys, xe, ye);
For I := 0 To High(Points) Do
FastSetPixel(ClientBMP, Points[i].X - xs, Points[i].Y - ys, 255);
If BmpName <> '' Then
SaveBitmap(ClientBMP, ScriptPath + BmpName + '.bmp');
SafeDrawBitmap(ClientBMP, GetDebugCanvas, 0, 0);
DisplayDebugImgWindow(Width, Height);

FreeBitmap(ClientBMP);
End
Except
FreeBitmap(ClientBMP);
End;
Result := True;
End;

massive630

2009-01-16 16:21:10

From: Cazax
I use DebugTPA by Wizzup:
Function DebugTPA(Points: TPointArray; BmpName: String): Boolean;

Var
Width, Height, ClientBMP, I: Integer;
xs, ys, xe, ye: Integer;

Begin
Try
Begin
xe := xs xor xs;
ye := ys xor ys;
xs := 1 shl 20;
ys := 1 shl 20;

For I := 0 To High(Points) Do
Begin
xs := Min(xs, Points[i].X);
ys := Min(ys, Points[i].Y);

xe := Max(xe, Points[i].X);
ye := Max(ye, Points[i].Y);
End;

Width := xe - xs;
Height := ye - ys;

DisplayDebugImgWindow(0, 0);
DisplayDebugImgWindow(Width, Height);
ClientBMP := BitmapFromString(Width, Height, '');

CopyClientToBitmap(ClientBMP, xs, ys, xe, ye);
For I := 0 To High(Points) Do
FastSetPixel(ClientBMP, Points[i].X - xs, Points[i].Y - ys, 255);
If BmpName <> '' Then
SaveBitmap(ClientBMP, ScriptPath + BmpName + '.bmp');
SafeDrawBitmap(ClientBMP, GetDebugCanvas, 0, 0);
DisplayDebugImgWindow(Width, Height);

FreeBitmap(ClientBMP);
End
Except
FreeBitmap(ClientBMP);
End;
Result := True;
End;


Wow thanks. I hate to ask, but i guess ive gotta ask to learn: how in gods name would i use this?

Cazax

2009-01-16 16:55:57

a TPA is an array of tpoints, so you just input your points:
DebugTPA(Points, '');
You can change '' to something and it will save it as a bitmap.


Example:
procedure Debug;
Var
TPA : TPointArray;
Begin
FindColorsTolerance(TPA, Color, X1, Y1, X2, Y2, Tol);
DebugTPA(TPA, '');
End;

massive630

2009-01-17 09:43:32

Wow Cazex thanks alot. you've been very helpful. Rep.

Macho Man67

2009-01-25 12:26:36

Nice function! Could I use this in my upcoming script? I'll make sure to credit.

Shuttleu

2009-02-04 15:04:36

what is the differnace between TColor and Integer

~shut