2005-09-11 14:05:31 -04:00
|
|
|
unit varRings2;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
BaseVariation, XFormMan;
|
|
|
|
|
|
|
|
type
|
|
|
|
TVariationRings2 = class(TBaseVariation)
|
|
|
|
private
|
2006-01-05 13:24:25 -05:00
|
|
|
FVal, dx: double;
|
2005-09-11 14:05:31 -04:00
|
|
|
public
|
|
|
|
constructor Create;
|
|
|
|
|
|
|
|
class function GetName: string; override;
|
|
|
|
class function GetInstance: TBaseVariation; override;
|
|
|
|
|
|
|
|
class function GetNrVariables: integer; override;
|
|
|
|
class function GetVariableNameAt(const Index: integer): string; override;
|
|
|
|
|
|
|
|
function SetVariable(const Name: string; var value: double): boolean; override;
|
|
|
|
function GetVariable(const Name: string; var value: double): boolean; override;
|
|
|
|
|
2006-01-05 13:24:25 -05:00
|
|
|
procedure Prepare; override;
|
2005-09-11 14:05:31 -04:00
|
|
|
procedure CalcFunction; override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
Math;
|
|
|
|
|
2006-01-06 11:29:02 -05:00
|
|
|
{ TVariationRings2 }
|
2005-09-11 14:05:31 -04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2006-01-05 13:24:25 -05:00
|
|
|
procedure TVariationRings2.Prepare;
|
|
|
|
const
|
|
|
|
EPS = 1E-10;
|
|
|
|
begin
|
|
|
|
dx := sqr(FVal) + EPS;
|
|
|
|
end;
|
|
|
|
|
2005-09-11 14:05:31 -04:00
|
|
|
procedure TVariationRings2.CalcFunction;
|
|
|
|
var
|
2006-01-05 13:24:25 -05:00
|
|
|
r: double;
|
2005-09-11 14:05:31 -04:00
|
|
|
Length: double;
|
|
|
|
Angle: double;
|
|
|
|
begin
|
2006-01-05 13:24:25 -05:00
|
|
|
Length := sqrt(sqr(FTx^) + sqr(FTy^));
|
|
|
|
{ // all this range-checking crap only slows us down...
|
2005-09-11 14:05:31 -04:00
|
|
|
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
|
2006-01-05 13:24:25 -05:00
|
|
|
Angle := arctan2(FTx^, FTy^)
|
2005-09-11 14:05:31 -04:00
|
|
|
else
|
|
|
|
Angle := 0.0;
|
2006-01-05 13:24:25 -05:00
|
|
|
} // ...and besides, we don't need arctan() if we have Length!
|
2005-09-11 14:05:31 -04:00
|
|
|
|
2006-01-05 13:24:25 -05:00
|
|
|
// dx := sqr(FVal) + EPS; - we can precalc it!!!
|
|
|
|
// r := Length + dx - System.Int((Length + dx)/(2 * dx)) * 2 * dx - dx + Length * (1-dx);
|
2006-01-06 11:29:02 -05:00
|
|
|
// ^^^^......he he, lots of useless calculations......^^^^
|
2006-01-05 13:24:25 -05:00
|
|
|
r := vvar * (2 - dx * (System.Int((Length/dx + 1)/2) * 2 / Length + 1));
|
2005-09-11 14:05:31 -04:00
|
|
|
|
2006-01-05 13:24:25 -05:00
|
|
|
FPx^ := FPx^ + r * FTx^;
|
|
|
|
FPy^ := FPy^ + r * FTy^;
|
2005-09-11 14:05:31 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
constructor TVariationRings2.Create;
|
|
|
|
begin
|
|
|
|
FVal := Random * 2;
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class function TVariationRings2.GetInstance: TBaseVariation;
|
|
|
|
begin
|
|
|
|
Result := TVariationRings2.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class function TVariationRings2.GetName: string;
|
|
|
|
begin
|
|
|
|
Result := 'rings2';
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class function TVariationRings2.GetVariableNameAt(const Index: integer): string;
|
|
|
|
begin
|
|
|
|
case Index Of
|
|
|
|
0: Result := 'rings2_val';
|
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function TVariationRings2.SetVariable(const Name: string; var value: double): boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if Name = 'rings2_val' then begin
|
|
|
|
FVal := Value;
|
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class function TVariationRings2.GetNrVariables: integer;
|
|
|
|
begin
|
|
|
|
Result := 1
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function TVariationRings2.GetVariable(const Name: string; var value: double): boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if Name = 'rings2_val' then begin
|
|
|
|
Value := FVal;
|
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
initialization
|
|
|
|
RegisterVariation(TVariationRings2);
|
|
|
|
end.
|