SRL Archive - SRL Archives

TPAMods


Torrent of Flame

2009-05-13 23:12:10

Works out the variables needed in a TPA for you in a script, so you dont have to spend a while working out the mods yourself. There is a procedure that can do this in the OpenDev SVN, but this procedure only does this job, so can be used many times, whereas the procedure by Nava2 is only really used once. This means that this can be used in many different TPA procedures.

{*******************************************************************************
function function TPAMods(var MidColour: integer; var HueMod, SatMod: Extended; Colors: TIntegerArray): boolean;
By: TorrentOfFlame
Description: Works out the MidColour, Tolerance, Hue Modifier and Saturation Modifier for TPA's based on inputted
values
*******************************************************************************}
function TPAMods(var MidColour, Tolerance: integer; var HueMod, SatMod: Extended; Colors: TIntegerArray): boolean;
var
H, S, L, Tol: Extended;
i, ii: integer;
HSLColor: Array[1..3] of Extended;
HSL: Array[0..1] of Array[1..3] of Extended;
begin
for i := 0 to High(Colors) do
begin
ColortoHSL(Colors[i], HSLColor[1], HSLColor[2], HSLColor[3]);
for ii:= 1 to 3 do
begin
HSL[0][ii] := MinE(HSLColor[ii], HSL[0][ii]);
HSL[1][ii] := MaxE(HSLColor[ii], HSL[1][ii]);
end;
end;
H := HSL[1][1] - HSL[0][1];
S := HSL[1][2] - HSL[0][2];
L := HSL[1][3] - HSL[0][3];
MidColour := HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2);
HueMod := (H/L);
SatMod := (S/L);
Tol := L;
if (MidColour <= 0) then
begin
WriteLn('TPA Variables not found.');
Result := False;
end else
Result := True;
Tolerance := Trunc(Tol + 0.5);
end;


In use;

function MyFirstTPA: Boolean;
var
CTS, i, x, y, MiddleColour, Tolerance: Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
HueModifier, SatModifier: Extended;
begin
TPAMods(MiddleColour, Tolerance, HueModifier, SatModifier, [3241318, 2119755, 2645844, 3240035]);
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(HueModifier, SatModifier);
{ ClearDebug;
Writeln('Hue Modifier is: '+FloatToStr(HueModifier)+'');
Writeln('Saturation Modifier is: '+FloatToStr(SatModifier)+'');
Writeln('Middle Colour is: '+IntToStr(MiddleColour)+'');
Writeln('Tolerance is: '+IntToStr(Tolerance)+''); }
FindColorsSpiralTolerance(MSCX, MSCY, TPA, MiddleColour, MSX1, MSY1, MSX2, MSY2, Tolerance);
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 15, 15);
for i := 0 to High(ATPA) do
begin
Result := True;
MiddleTPAEx(ATPA[i], x, y);
end;
end;

So it works out the HueMod, SatMod and MidColour for you.

With those colours used in the function, it gives this;

Hue Modifier is: 0.630916476913401
Saturation Modifier is: 1.43373490004568
Middle Colour is: 2108467
Tolerance is: 33
Successfully executed


~ToF

Torrent of Flame

2009-05-14 14:40:29

Nothing? :'(

MylesMadness

2009-05-14 15:01:22

Sexy. So its ACA on the fly kinda?

Torrent of Flame

2009-05-14 15:06:19

From: MylesMadness
Sexy. So its ACA on the fly kinda?


How do you mean? Sorta like a quick ACA?

MylesMadness

2009-05-14 15:08:32

From: Torrent of Flame
How do you mean? Sorta like a quick ACA?
I use ACA when I just plug in a bunch of colors on a object and have ACA spit out the color, tolerence and hue and sat mods. I don't use the object finder thingy

Torrent of Flame

2009-05-14 15:10:22

From: MylesMadness
I use ACA when I just plug in a bunch of colors on a object and have ACA spit out the color, tolerence and hue and sat mods. I don't use the object finder thingy


Well yeah. I suppose this is a quicker way of doing that, which doesnt actually require you to do anything because the procedure does it all for you, so you just include the procedure and dont have to open ACA :P

Nava2

2009-05-14 15:34:02

Uhm. Mine isn't done haha. But mine returns a lot more information.

Just so you are aware.

Torrent of Flame

2009-05-14 15:35:17

From: Nava2
Uhm. Mine isn't done haha. But mine returns a lot more information.

Just so you are aware.


Isnt is in the OpenSVN at the momoent though? And I know yours returns alot more information, you commented that it should only be used once because of this fact, whereas this can be used many times in one script for different TPA's.

Nava2

2009-05-15 08:44:39

Eh, I need to fix mine :p

Its not slow, it just can be if its abused xD

Torrent of Flame

2009-05-15 11:04:00

From: Nava2
Eh, I need to fix mine :p

Its not slow, it just can be if its abused xD


Still, my procedure is for like.. just doing it quickly, now OBEY ME and put it in OpenDEV (see I would but Im scared of teh consequences, that and I'm not sure what place to put it)

Da 0wner

2009-05-15 11:52:19

Make it find tolerance?

Torrent of Flame

2009-05-15 19:39:00

From: Da 0wner
Make it find tolerance?


Updated it to do so! Check first post now.

Da 0wner

2009-05-16 11:54:14

Oh this is nice :D.
I might use :D.

Torrent of Flame

2009-05-16 13:47:12

:D.

Nice to know it could be considered useful :P

Da 0wner

2009-05-17 05:14:00

Well, this should be added into SRL, I swear.

Nava2

2009-05-17 08:13:27

I'm going to fix up mine and add it.. no offence, but why put a smaller one in when a larger should be.. o.O

Camaro'

2009-05-17 08:13:29

From: Da 0wner
Well, this should be added into SRL, I swear.


2nd

Torrent of Flame

2009-05-17 13:37:24

From: Nava2
I'm going to fix up mine and add it.. no offence, but why put a smaller one in when a larger should be.. o.O


Dude, I dont care whether it is or not, but mine is set out to do a single function, so it is used quicker. Why should people be forced to use your procedure which works out EVERYTHING when they only want to work out the TPA stuff?

But whatever. If it isnt included, it can just be copied and pasted into scripts and used that way.

Nava2

2009-05-17 18:22:37

From: Torrent of Flame
Dude, I dont care whether it is or not, but mine is set out to do a single function, so it is used quicker. Why should people be forced to use your procedure which works out EVERYTHING when they only want to work out the TPA stuff?

But whatever. If it isnt included, it can just be copied and pasted into scripts and used that way.


If you check out Color.scar you can see where its applied, the speed isn't significantly changed.

Debug Color Array Output:
Used 31 colours.

RGB:
R Min: 103
R Max: 143
R Avg: 128
G Min: 94
G Max: 140
G Avg: 119
B Min: 78
B Max: 113
B Avg: 100
Best Color: 6584192 CTS 0 - Tol: 46 CTS 1 - Tol: 71

HSL:
H Min: 8.6206890642643
H Max: 15.0000005960464
H Avg: 11.0905814170837
S Min: 11.0236242413521
S Max: 11.811026185751
S Avg: 12.3254387825727
L Min: 35.4901969432831
L Max: 50.1960813999176
L Avg: 44.7189553578695
Best Color: 6584192 Tol: 15 HMod: 8.95862072904905 SMod: 8.59842505057653

XYZ:
X Min: 10.971368270166
X Max: 23.6864119733873
X Avg: 18.0585327021734
Y Min: 11.4390302816602
Y Max: 25.7880611252297
Y Avg: 18.9325033137383
Z Min: 8.83742737584877
Z Max: 19.351970137414
Z Avg: 15.0404449375161
Best Color: 6649985

DebugColorArray took: 141 ms to complete.

I've tossed mine into Color.scar in the dev SVN.

Torrent of Flame

2009-05-17 18:34:28

From: Nava2
If you check out Color.scar you can see where its applied, the speed isn't significantly changed.


{Note this should only be run once as it can be slow.}
;)

Nava2

2009-05-18 01:23:45

Pretty sure I tested it.. with 31 colours it was only 150ms. Thats not slow.. o.O

And if you were using this during run time, I don't see HOW you could have more than 5… =/

Torrent of Flame

2009-05-18 10:33:16

I dont see why you would need all of that. When I first started using TPA's that stuff confused me anyway, as in I didnt know what one I was meant to be using. Whatever, I mean your the Dev so..

marpis

2009-05-20 14:17:58

So if i understand this right, it looks for colors and chooses the best Hue and Saturation modifiers for ColorSpeed2Modifiers() function?

What makes those values the best?

edit: No, it doesnt look for any colors, just pure maths… but where do those values come from and why should i use them?

Nava2

2009-05-20 17:04:16

From: marpis
So if i understand this right, it looks for colors and chooses the best Hue and Saturation modifiers for ColorSpeed2Modifiers() function?

What makes those values the best?

edit: No, it doesnt look for any colors, just pure maths… but where do those values come from and why should i use them?


Its for accurate colour finding… :) Look up CTS 0, 1, 2.

marpis

2009-05-22 21:08:19

Thanks alot mate, i tried using this in my fighter and now it's soo much more accurate! :) i used to have Huemod and Satmod both 0.4 or 0.2 always, and difficult objects such as brown chickens were ocassionaly hard to find. Now i have a procedure that gets hue and sat mods, then starts at tolerance 10 finding colors, and if Length(TPA) > 1000, it decreases tolerance by 1 and does the same thing again. This way it's amazingly accurate!

But the tolerance finder is kinda useless when it spits out 30+ all the time :p

THIS SHOULD TOTALLY BE ADDED!
edit: ofc i save the hue/sat mods and tolerance to variables so that i don't need to test more than once

Nava2

2009-05-23 10:11:37

It is added.

Torrent of Flame

2009-05-28 20:49:13

Nava2, is that yours is now added, or mine is added?

Nava2

2009-05-28 23:07:05

Mine. Sorry.

Torrent of Flame

2009-05-28 23:13:08

^_^

No problems