172 lines
4.9 KiB
ObjectPascal
172 lines
4.9 KiB
ObjectPascal
|
{
|
||
|
Apophysis Copyright (C) 2001-2004 Mark Townsend
|
||
|
Apophysis Copyright (C) 2005-2006 Ronald Hordijk, Piotr Borys, Peter Sdobnov
|
||
|
Apophysis Copyright (C) 2007-2008 Piotr Borys, Peter Sdobnov
|
||
|
|
||
|
Apophysis "3D hack" Copyright (C) 2007-2008 Peter Sdobnov
|
||
|
Apophysis "7X" Copyright (C) 2009-2010 Georg Kiehne
|
||
|
Apophysis AV "Phoenix Edition" Copyright (C) 2021 Alice V. Koryagina
|
||
|
|
||
|
This program is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation; either version 2 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||
|
}
|
||
|
|
||
|
unit varHypertile2;
|
||
|
|
||
|
interface
|
||
|
|
||
|
uses
|
||
|
BaseVariation, XFormMan;
|
||
|
|
||
|
type
|
||
|
TVariationHypertile2 = class(TBaseVariation)
|
||
|
private
|
||
|
hypertile2_p, hypertile2_q: integer;
|
||
|
pa, r: double;
|
||
|
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;
|
||
|
function ResetVariable(const Name: string): boolean; override;
|
||
|
|
||
|
procedure Prepare; override;
|
||
|
procedure CalcFunction; override;
|
||
|
end;
|
||
|
|
||
|
implementation
|
||
|
|
||
|
uses
|
||
|
Math;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
procedure TVariationHypertile2.Prepare;
|
||
|
var
|
||
|
cp, r2: double;
|
||
|
begin
|
||
|
pa := PI2 / hypertile2_p;
|
||
|
cp := cos(pa);
|
||
|
r2 := 1 - (cp - 1) / (cp + cos(PI2 / hypertile2_q));
|
||
|
if (r2 > 0) then
|
||
|
r := 1 / sqrt(r2)
|
||
|
else
|
||
|
r := 1;
|
||
|
end;
|
||
|
|
||
|
procedure TVariationHypertile2.CalcFunction;
|
||
|
var
|
||
|
sina, cosa, x, y, u, v, s, t, vr: double;
|
||
|
begin
|
||
|
u := FTx^ + r;
|
||
|
v := FTy^;
|
||
|
s := r * FTx^ + 1;
|
||
|
t := r * FTy^;
|
||
|
|
||
|
vr := vvar / (sqr(s) + sqr(t));
|
||
|
x := u * s + v * t;
|
||
|
y := v * s - u * t;
|
||
|
|
||
|
SinCos(random(32767) * pa, sina, cosa);
|
||
|
|
||
|
FPx^ := FPx^ + vr * (x * cosa + y * sina);
|
||
|
FPy^ := FPy^ + vr * (y * cosa - x * sina);
|
||
|
// FPz^ := FPz^ + VVAR * FTz^;
|
||
|
end;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
constructor TVariationHypertile2.Create;
|
||
|
begin
|
||
|
hypertile2_p := 3;
|
||
|
hypertile2_q := 7;
|
||
|
end;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
class function TVariationHypertile2.GetInstance: TBaseVariation;
|
||
|
begin
|
||
|
Result := TVariationHypertile2.Create;
|
||
|
end;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
class function TVariationHypertile2.GetName: string;
|
||
|
begin
|
||
|
Result := 'hypertile2';
|
||
|
end;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
function TVariationHypertile2.GetVariableNameAt(const Index: integer): string;
|
||
|
begin
|
||
|
case Index Of
|
||
|
0: Result := 'hypertile2_p';
|
||
|
1: Result := 'hypertile2_q';
|
||
|
else
|
||
|
Result := '';
|
||
|
end
|
||
|
end;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
function TVariationHypertile2.SetVariable(const Name: string; var value: double): boolean;
|
||
|
begin
|
||
|
Result := False;
|
||
|
if Name = 'hypertile2_p' then begin
|
||
|
if Value < 3 then Value := 3;
|
||
|
hypertile2_p := Round(Value);
|
||
|
Result := True;
|
||
|
end else if Name = 'hypertile2_q' then begin
|
||
|
if Value < 3 then Value := 3;
|
||
|
hypertile2_q := Round(Value);
|
||
|
Result := True;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
function TVariationHypertile2.ResetVariable(const Name: string): boolean;
|
||
|
begin
|
||
|
Result := False;
|
||
|
if Name = 'hypertile2_p' then begin
|
||
|
hypertile2_p := 3;
|
||
|
Result := True;
|
||
|
end else if Name = 'hypertile2_q' then begin
|
||
|
hypertile2_q := 7;
|
||
|
Result := True;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
function TVariationHypertile2.GetNrVariables: integer;
|
||
|
begin
|
||
|
Result := 2;
|
||
|
end;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
function TVariationHypertile2.GetVariable(const Name: string; var value: double): boolean;
|
||
|
begin
|
||
|
Result := False;
|
||
|
if Name = 'hypertile2_p' then begin
|
||
|
Value := hypertile2_p;
|
||
|
Result := True;
|
||
|
end else if Name = 'hypertile2_q' then begin
|
||
|
Value := hypertile2_q;
|
||
|
Result := True;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
initialization
|
||
|
RegisterVariation(TVariationClassLoader.Create(TVariationHypertile2), false, false);
|
||
|
end.
|