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.
In use;
So it works out the HueMod, SatMod and MidColour for you.
With those colours used in the function, it gives this;
~ToF
{*******************************************************************************
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