apophysis/2.10/Source/varJuliaN.pas

391 lines
8.1 KiB
ObjectPascal
Raw Normal View History

2006-03-06 10:50:29 -05:00
unit varJuliaN;
interface
uses
BaseVariation, XFormMan;
const
2007-10-28 09:26:48 -04:00
var_name = 'julian';
2006-03-06 10:50:29 -05:00
var_n_name='julian_power';
var_c_name='julian_dist';
{$define _ASM_}
2006-03-06 10:50:29 -05:00
type
TVariationJulian = class(TBaseVariation)
private
N: integer;
c: double;
2007-10-28 09:26:48 -04:00
absN: integer;
cN, vvar2: double;
2006-03-06 10:50:29 -05:00
procedure CalcPower1;
procedure CalcPowerMinus1;
procedure CalcPower2;
procedure CalcPowerMinus2;
2006-03-06 10:50:29 -05:00
public
constructor Create;
class function GetName: string; override;
class function GetInstance: TBaseVariation; override;
2008-02-28 10:46:59 -05:00
function GetNrVariables: integer; override;
function GetVariableNameAt(const Index: integer): string; override;
2006-03-06 10:50:29 -05:00
function SetVariable(const Name: string; var value: double): boolean; override;
function GetVariable(const Name: string; var value: double): boolean; override;
function ResetVariable(const Name: string): boolean; override;
2006-03-06 10:50:29 -05:00
procedure Prepare; override;
procedure CalcFunction; override;
procedure GetCalcFunction(var f: TCalcFunction); override;
2006-03-06 10:50:29 -05:00
end;
implementation
uses
2007-10-28 09:26:48 -04:00
Math;
2006-03-06 10:50:29 -05:00
// TVariationJulian
///////////////////////////////////////////////////////////////////////////////
constructor TVariationJulian.Create;
begin
N := random(5) + 2;
c := 1.0;
end;
procedure TVariationJulian.Prepare;
begin
2007-10-28 09:26:48 -04:00
absN := abs(N);
cN := c / N / 2;
vvar2 := vvar * sqrt(2)/2;
2006-03-06 10:50:29 -05:00
end;
///////////////////////////////////////////////////////////////////////////////
procedure TVariationJulian.GetCalcFunction(var f: TCalcFunction);
begin
2006-06-02 08:31:47 -04:00
if c = 1 then begin
if N = 2 then f := CalcPower2
else if N = -2 then f := CalcPowerMinus2
else if N = 1 then f := CalcPower1
else if N = -1 then f := CalcPowerMinus1
else f := CalcFunction;
end
else f := CalcFunction;
end;
///////////////////////////////////////////////////////////////////////////////
2006-03-06 10:50:29 -05:00
procedure TVariationJulian.CalcFunction;
{$ifndef _ASM_}
2006-03-06 10:50:29 -05:00
var
r: double;
sina, cosa: extended;
begin
2007-10-28 09:26:48 -04:00
sincos((arctan2(FTy^, FTx^) + 2*pi*random(absN)) / N, sina, cosa);
r := vvar * Math.Power(sqr(FTx^) + sqr(FTy^), cN);
2006-03-06 10:50:29 -05:00
FPx^ := FPx^ + r * cosa;
FPy^ := FPy^ + r * sina;
{$else}
asm
mov edx, [eax + FTx]
2007-10-28 09:26:48 -04:00
fld qword ptr [edx] // FTx
fld qword ptr [edx + 8] // FTy
fld qword ptr [eax + cN]
2006-03-06 10:50:29 -05:00
fld st(2)
fmul st, st
2007-10-28 09:26:48 -04:00
fld st(2)
2006-03-06 10:50:29 -05:00
fmul st, st
faddp
// --- x^y = 2^(y*log2(x))
fyl2x
fld st
frndint
fsub st(1), st
fxch st(1)
f2xm1
fld1
fadd
fscale
fstp st(1)
// ---
2007-10-28 09:26:48 -04:00
fmul qword ptr [eax + vvar]
fxch st(2)
fpatan
mov ecx, eax
mov eax, dword ptr [eax + absN]
call System.@RandInt
push eax
fild dword ptr [esp]
add esp, 4
fldpi
fadd st, st
fmulp
faddp
fidiv dword ptr [ecx + N]
2006-03-06 10:50:29 -05:00
fsincos
2007-10-28 09:26:48 -04:00
fmul st, st(2)
2006-03-06 10:50:29 -05:00
mov edx, [ecx + FPx]
2007-10-28 09:26:48 -04:00
fadd qword ptr [edx] // FPx
2006-03-06 10:50:29 -05:00
fstp qword ptr [edx]
fmulp
2007-10-28 09:26:48 -04:00
fadd qword ptr [edx + 8] // FPy
fstp qword ptr [edx + 8]
2006-03-06 10:50:29 -05:00
fwait
{$endif}
end;
procedure TVariationJulian.CalcPower2;
{$ifndef _ASM_}
var
2007-10-28 09:26:48 -04:00
d: double;
begin
2007-10-28 09:26:48 -04:00
d := sqrt( sqrt(sqr(FTx^) + sqr(FTy^)) + FTx^ );
2007-10-28 09:26:48 -04:00
if random(2) = 0 then begin
FPx^ := FPx^ + vvar2 * d;
FPy^ := FPy^ + vvar2 / d * FTy^;
end
else begin
FPx^ := FPx^ - vvar2 * d;
FPy^ := FPy^ - vvar2 / d * FTy^;
end;
{$else}
asm
mov edx, [eax + FTx]
2007-10-28 09:26:48 -04:00
fld qword ptr [edx + 8] // FTy
fld qword ptr [edx] // FTx
fld st(1)
2007-10-28 09:26:48 -04:00
fmul st,st
fld st(1)
2007-10-28 09:26:48 -04:00
fmul st,st
faddp
fsqrt
2007-10-28 09:26:48 -04:00
faddp
fsqrt
2007-10-28 09:26:48 -04:00
fld qword ptr [eax + vvar2]
mov ecx,eax
mov eax,2
call System.@RandInt
shr eax,1
jc @skip
fchs
@skip:
fmul st(2),st
fmul st,st(1)
mov edx, [ecx + FPx]
fadd qword ptr [edx]
fstp qword ptr [edx]
2007-10-28 09:26:48 -04:00
fdivp st(1),st
fadd qword ptr [edx + 8]
fstp qword ptr [edx + 8]
fwait
{$endif}
end;
procedure TVariationJulian.CalcPowerMinus2;
{$ifndef _ASM_}
var
2007-10-28 09:26:48 -04:00
r, xd: double;
begin
2007-10-28 09:26:48 -04:00
r := sqrt(sqr(FTx^) + sqr(FTy^));
xd := r + FTx^;
2007-10-28 09:26:48 -04:00
r := vvar / sqrt(r * (sqr(Fty^) + sqr(xd)) );
if random(2) = 0 then begin
FPx^ := FPx^ + r * xd;
FPy^ := FPy^ - r * FTy^;
end
else begin
FPx^ := FPx^ - r * xd;
FPy^ := FPy^ + r * FTy^;
end;
{$else}
asm
2007-10-28 09:26:48 -04:00
mov edx, [eax + FTx]
fld qword ptr [edx + 8]
fld qword ptr [edx]
fld st(1)
2007-10-28 09:26:48 -04:00
fmul st,st
fld st(1)
2007-10-28 09:26:48 -04:00
fmul st,st
faddp
fsqrt
2007-10-28 09:26:48 -04:00
fadd st(1),st
fld st(1)
fmul st,st
fld st(3)
fmul st,st
faddp
fmulp
fsqrt
2007-10-28 09:26:48 -04:00
fdivr qword ptr [eax + vvar]
mov ecx,eax
mov eax,2
call System.@RandInt
shr eax,1
jc @skip
fchs
@skip:
fmul st(1),st
fmulp st(2),st
mov edx, [ecx + FPx]
2007-10-28 09:26:48 -04:00
fsubr qword ptr [edx]
fstp qword ptr [edx]
2007-10-28 09:26:48 -04:00
fadd qword ptr [edx + 8]
fstp qword ptr [edx + 8]
fwait
{$endif}
end;
procedure TVariationJulian.CalcPower1;
{$ifndef _ASM_}
begin
FPx^ := FPx^ + vvar * FTx^;
FPy^ := FPy^ + vvar * FTy^;
{$else}
asm
mov edx, [eax + FTx] //[eax + FTy]
2007-07-12 10:40:00 -04:00
fld qword ptr [edx]
2007-10-28 09:26:48 -04:00
// mov edx, [eax + FTx]
fld qword ptr [edx + 8]
fld qword ptr [eax + vvar]
fmul st(2), st
fmulp
// mov edx, [eax + FPx]
fadd qword ptr [edx + 16]
fstp qword ptr [edx + 16]
// mov edx, [eax + FPy]
fadd qword ptr [edx + 24]
fstp qword ptr [edx + 24]
fwait
{$endif}
end;
procedure TVariationJulian.CalcPowerMinus1;
{$ifndef _ASM_}
var
r: double;
begin
r := vvar / (sqr(FTx^) + sqr(FTy^));
FPx^ := FPx^ + r * FTx^;
FPy^ := FPy^ - r * FTy^;
{$else}
asm
mov edx, [eax + FTx]
fld qword ptr [edx + 8] // FTy
// mov edx, [eax + FTx]
fld qword ptr [edx] // FTx
fld st(1)
fmul st, st
fld st(1)
fmul st, st
faddp
fdivr qword ptr [eax + vvar]
fmul st(2), st
fmulp
// mov edx, [eax + FPx]
fadd qword ptr [edx + 16] // FPx
fstp qword ptr [edx + 16] // FPx
// mov edx, [eax + FPy]
fsubr qword ptr [edx + 24] // FPy
fstp qword ptr [edx + 24] // FPy
fwait
{$endif}
2006-03-06 10:50:29 -05:00
end;
///////////////////////////////////////////////////////////////////////////////
class function TVariationJulian.GetInstance: TBaseVariation;
begin
Result := TVariationJulian.Create;
end;
///////////////////////////////////////////////////////////////////////////////
class function TVariationJulian.GetName: string;
begin
2007-10-28 09:26:48 -04:00
Result := var_name;
2006-03-06 10:50:29 -05:00
end;
///////////////////////////////////////////////////////////////////////////////
2008-02-28 10:46:59 -05:00
function TVariationJulian.GetVariableNameAt(const Index: integer): string;
2006-03-06 10:50:29 -05:00
begin
case Index of
0: Result := var_n_name;
1: Result := var_c_name;
else
Result := '';
end
end;
///////////////////////////////////////////////////////////////////////////////
function TVariationJulian.SetVariable(const Name: string; var value: double): boolean;
begin
Result := False;
if Name = var_n_name then begin
N := Round(Value);
if N = 0 then N := 1;
Value := N;
Result := True;
end
else if Name = var_c_name then begin
c := value;
Result := True;
end;
end;
function TVariationJulian.ResetVariable(const Name: string): boolean;
begin
Result := False;
if Name = var_n_name then begin
2006-09-06 08:33:00 -04:00
if N = 2 then N := -2
else N := 2;
Result := True;
end
else if Name = var_c_name then begin
c := 1;
Result := True;
2006-03-06 10:50:29 -05:00
end;
end;
///////////////////////////////////////////////////////////////////////////////
2008-02-28 10:46:59 -05:00
function TVariationJulian.GetNrVariables: integer;
2006-03-06 10:50:29 -05:00
begin
Result := 2;
end;
///////////////////////////////////////////////////////////////////////////////
function TVariationJulian.GetVariable(const Name: string; var value: double): boolean;
begin
Result := False;
if Name = var_n_name then begin
Value := N;
Result := true;
end
else if Name = var_c_name then begin
Value := c;
Result := true;
end;
end;
///////////////////////////////////////////////////////////////////////////////
initialization
2008-02-24 07:48:52 -05:00
RegisterVariation(TVariationClassLoader.Create(TVariationJulian));
2006-03-06 10:50:29 -05:00
end.