2005-09-11 14:05:31 -04:00
|
|
|
unit varFan2;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
BaseVariation, XFormMan;
|
|
|
|
|
|
|
|
type
|
|
|
|
TVariationFan2 = class(TBaseVariation)
|
|
|
|
private
|
2006-01-05 13:24:25 -05:00
|
|
|
FX, FY: double;
|
|
|
|
dy, dx, dx2: 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
|
|
|
{ TVariationFan2 }
|
2005-09-11 14:05:31 -04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2006-01-05 13:24:25 -05:00
|
|
|
procedure TVariationFan2.Prepare;
|
2005-09-11 14:05:31 -04:00
|
|
|
const
|
|
|
|
EPS = 1E-10;
|
2006-01-05 13:24:25 -05:00
|
|
|
begin
|
|
|
|
dy := FY;
|
|
|
|
dx := pi * (sqr(FX) + EPS);
|
|
|
|
dx2 := dx/2;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVariationFan2.CalcFunction;
|
2005-09-11 14:05:31 -04:00
|
|
|
var
|
2006-01-05 13:24:25 -05:00
|
|
|
r, a : double;
|
|
|
|
sinr, cosr: double;
|
2005-09-11 14:05:31 -04:00
|
|
|
Angle: double;
|
|
|
|
begin
|
2006-01-05 13:24:25 -05:00
|
|
|
{
|
2005-09-11 14:05:31 -04:00
|
|
|
r := sqrt(FTx^ * FTx^ + FTy^ * FTy^);
|
|
|
|
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
|
|
|
|
Angle := arctan2(FTx^, FTy^)
|
|
|
|
else
|
|
|
|
Angle := 0.0;
|
|
|
|
|
|
|
|
dy := FY;
|
|
|
|
dx := PI * (sqr(FX) + EPS);
|
|
|
|
dx2 := dx/2;
|
|
|
|
|
|
|
|
t := Angle+dy - System.Int((Angle + dy)/dx) * dx;
|
|
|
|
if (t > dx2) then
|
|
|
|
a := Angle - dx2
|
|
|
|
else
|
|
|
|
a := Angle + dx2;
|
|
|
|
|
2005-10-23 03:41:19 -04:00
|
|
|
FPx^ := FPx^ + vvar * r * sin(a);
|
|
|
|
FPy^ := FPy^ + vvar * r * cos(a);
|
2006-01-05 13:24:25 -05:00
|
|
|
}
|
|
|
|
Angle := arctan2(FTx^, FTy^);
|
|
|
|
if System.Frac((Angle + dy)/dx) > 0.5 then
|
|
|
|
a := Angle - dx2
|
|
|
|
else
|
|
|
|
a := Angle + dx2;
|
|
|
|
asm // SinCos(a, sinr, cosr);
|
|
|
|
FLD qword ptr [a]
|
|
|
|
FSINCOS
|
|
|
|
FSTP qword ptr [sinr]
|
|
|
|
FSTP qword ptr [cosr]
|
|
|
|
FWAIT
|
|
|
|
end;
|
|
|
|
r := vvar * sqrt(sqr(FTx^) + sqr(FTy^));
|
|
|
|
FPx^ := FPx^ + r * cosr;
|
|
|
|
FPy^ := FPy^ + r * sinr;
|
2005-09-11 14:05:31 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
constructor TVariationFan2.Create;
|
|
|
|
begin
|
2006-01-06 11:29:02 -05:00
|
|
|
FX := 2 * Random - 1;
|
|
|
|
FY := 2 * Random - 1;
|
2005-09-11 14:05:31 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class function TVariationFan2.GetInstance: TBaseVariation;
|
|
|
|
begin
|
|
|
|
Result := TVariationFan2.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class function TVariationFan2.GetName: string;
|
|
|
|
begin
|
|
|
|
Result := 'fan2';
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class function TVariationFan2.GetVariableNameAt(const Index: integer): string;
|
|
|
|
begin
|
|
|
|
case Index Of
|
|
|
|
0: Result := 'fan2_x';
|
|
|
|
1: Result := 'fan2_y';
|
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function TVariationFan2.SetVariable(const Name: string; var value: double): boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if Name = 'fan2_x' then begin
|
|
|
|
FX := Value;
|
|
|
|
Result := True;
|
|
|
|
end else if Name = 'fan2_y' then begin
|
|
|
|
FY := Value;
|
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class function TVariationFan2.GetNrVariables: integer;
|
|
|
|
begin
|
|
|
|
Result := 2
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function TVariationFan2.GetVariable(const Name: string; var value: double): boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if Name = 'fan2_x' then begin
|
|
|
|
Value := FX;
|
|
|
|
Result := True;
|
|
|
|
end else if Name = 'fan2_y' then begin
|
|
|
|
Value := FY;
|
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
initialization
|
|
|
|
RegisterVariation(TVariationFan2);
|
|
|
|
end.
|