Apophysis-AV/Variations/varPower.pas

128 lines
2.7 KiB
ObjectPascal
Raw Permalink Normal View History

{ Apophysis AV "Phoenix Edition" Copyright (C) 2021-2022 Alice V. Koryagina }
2022-03-08 12:25:51 -05:00
unit varPower;
interface
uses
BaseVariation, XFormMan;
type
TVariationPower = class(TBaseVariation)
private
use3D: byte;
procedure Calc3D;
2022-03-08 12:25:51 -05:00
public
constructor Create;
class function GetName: string; override;
class function GetInstance: TBaseVariation; override;
function GetNrVariables: integer; override;
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;
2022-03-08 12:25:51 -05:00
procedure CalcFunction; override;
procedure GetCalcFunction(var f: TCalcFunction); override;
2022-03-08 12:25:51 -05:00
end;
implementation
uses
Math;
////////////////////////
procedure TVariationPower.GetCalcFunction(var f: TCalcFunction);
begin
if use3D <> 0 then f := Calc3D // AV: added optional 3d-support
else f := CalcFunction;
end;
procedure TVariationPower.Calc3D; // AV
var
r, FSinA, FCosA: double;
begin
r := sqrt(sqr(FTx^) + sqr(FTy^) + sqr(FTz^)) + 1E-300;
FSinA := FTx^ / r;
FCosA := FTy^ / r;
r := vvar * Math.Power(r, FSinA);
FPx^ := FPx^ + r * FCosA;
FPy^ := FPy^ + r * FSinA;
// transform the plane into 3d-shape
r := vvar * Math.Power(r, FCosA);
FPz^ := FPz^ + r * FCosA; //FSinA;
end;
2022-03-08 12:25:51 -05:00
procedure TVariationPower.CalcFunction;
var
r, FSinA, FCosA: double;
2022-03-08 12:25:51 -05:00
begin
r := sqrt(sqr(FTx^) + sqr(FTy^)) + 1E-300;
FSinA := FTx^ / r;
FCosA := FTy^ / r;
r := vvar * Math.Power(r, FSinA);
2022-03-08 12:25:51 -05:00
FPx^ := FPx^ + r * FCosA;
FPy^ := FPy^ + r * FSinA;
end;
constructor TVariationPower.Create;
begin
inherited Create;
use3D := 0;
2022-03-08 12:25:51 -05:00
end;
class function TVariationPower.GetInstance: TBaseVariation;
begin
Result := TVariationPower.Create;
end;
class function TVariationPower.GetName: string;
begin
Result := 'power';
end;
function TVariationPower.GetNrVariables: integer;
begin
Result := 1;
end;
function TVariationPower.GetVariableNameAt(const Index: integer): string;
begin
case Index of
0: Result := 'power_use3D';
else
Result := '';
end;
end;
function TVariationPower.GetVariable(const Name: string;
var value: double): boolean;
begin
Result := False;
if Name = 'power_use3D' then begin
Value := use3D;
Result := True;
end;
end;
function TVariationPower.SetVariable(const Name: string;
var value: double): boolean;
begin
Result := False;
if Name = 'power_use3D' then begin
if (Value > 1) then Value := 1;
if (Value < 0) then Value := 0;
use3D := Round(Value);
Result := True;
end;
end;
2022-03-08 12:25:51 -05:00
//////////////////////////////
initialization
RegisterVariation(TVariationClassLoader.Create(TVariationPower), true, false);
2022-03-08 12:25:51 -05:00
end.