Gorilla.Terrain.Algorithm Unit Reference

Procedural terrain generation algorithms for creating realistic landscapes without heightmap images.

Unit: Gorilla.Terrain.Algorithm

Constants

const
  GORILLA_TERRAIN_SMOOTHING_MIN = 0;
  GORILLA_TERRAIN_SMOOTHING_MAX = 20;

Valid range for terrain smoothing iterations.

Types

TRandomTerrainAlgorithmType

type
  TRandomTerrainAlgorithmType = (Hill, DiamondSquare, Mandelbrot,
    PerlinNoise, Plateau, Brownian, Planar);

Enumeration of built-in procedural terrain algorithms.

Values:

  • Hill - Smooth rolling hills
  • DiamondSquare - Realistic peaks and valleys
  • Mandelbrot - Fractal pattern terrain
  • PerlinNoise - Smooth natural terrain with noise
  • Plateau - Flat elevated plateaus
  • Brownian - Particle-based simulation
  • Planar - Completely flat terrain

TPerlinNoiseInterpolation

type
  TPerlinNoiseInterpolation = (Linear, Cosine, Cubic);

Interpolation methods for Perlin noise terrain.

Values:

  • Linear - Fast, sharp edges
  • Cosine - Smooth, natural (recommended)
  • Cubic - Very smooth, slower

Classes

TRandomTerrainAlgorithm

Base class for procedural terrain algorithms.

Inheritance: TObject → TRandomTerrainAlgorithm

Properties

Size
property Size: Integer read FSize write FSize;

Grid size parameter used during computation. Actual size is typically (2^Size + 1).

Example: Size = 9 produces 513×513 grid

Methods

GetHeightMap
function GetHeightMap: TBitmap; virtual;

Generates and returns heightmap bitmap from internal data array.

Returns: TBitmap with grayscale height data (0=black/low, 255=white/high)

Remarks: Called automatically by TGorillaTerrain.RandomTerrain()

Creating Custom Algorithms

Extend this class to create custom terrain algorithms:

type
  TMyCustomTerrain = class(TRandomTerrainAlgorithm)
  protected
    procedure Generate;
  public
    function GetHeightMap: TBitmap; override;
  end;

procedure TMyCustomTerrain.Generate;
var
  x, y: Integer;
begin
  FWidth := 513;
  FHeight := 513;
  SetLength(FData, FWidth);
  for x := 0 to FWidth - 1 do
  begin
    SetLength(FData[x], FHeight);
    for y := 0 to FHeight - 1 do
      FData[x][y] := YourHeightFunction(x, y);  // 0.0 to 1.0
  end;
end;

function TMyCustomTerrain.GetHeightMap: TBitmap;
begin
  Generate;
  Result := inherited GetHeightMap;
end;

THillRandomTerrain

Generates smooth procedural hills using radius-based height calculations.

Inheritance: TRandomTerrainAlgorithm → THillRandomTerrain

Properties

Hills
property Hills: Integer read FHills write FHills;

Number of hills to generate.

Default: 20

MinRadius
property MinRadius: Integer read FMinRadius write FMinRadius;

Minimum radius for generated hills.

Default: 10

MaxRadius
property MaxRadius: Integer read FMaxRadius write FMaxRadius;

Maximum radius for generated hills. Algorithm interpolates between min and max.

Default: 100

Example

var
  LAlg: THillRandomTerrain;
begin
  LAlg := THillRandomTerrain.Create;
  try
    LAlg.Size := 9;
    LAlg.Hills := 30;
    LAlg.MinRadius := 20;
    LAlg.MaxRadius := 150;
    LTerrain.RandomTerrain(LAlg);
  finally
    LAlg.Free;
  end;
end;

TDiamondSquareTerrain

Popular algorithm for realistic random terrain with peaks and valleys.

Inheritance: TRandomTerrainAlgorithm → TDiamondSquareTerrain

Properties

MSeed
property MSeed: Integer read FMSeed write FMSeed;

Seed value for random number generation.

Default: 1000

Range: Affects randomness range (0 to MSeed)

Example

var
  LAlg: TDiamondSquareTerrain;
begin
  LAlg := TDiamondSquareTerrain.Create;
  try
    LAlg.Size := 9;
    LAlg.MSeed := 2000;  // More variation
    LTerrain.RandomTerrain(LAlg);
  finally
    LAlg.Free;
  end;
end;

TMandelbrotTerrain

Generates the Mandelbrot fractal set as terrain.

Inheritance: TRandomTerrainAlgorithm → TMandelbrotTerrain

Remarks: Produces fixed pattern (no randomness), useful as base for further processing.

Example

LTerrain.RandomTerrain(TRandomTerrainAlgorithmType.Mandelbrot);

TDiamondSquareBasedTerrain

Base class for algorithms combining diamond-square with other techniques.

Inheritance: TRandomTerrainAlgorithm → TDiamondSquareBasedTerrain

Properties

MSeed
property MSeed: Integer read FMSeed write FMSeed;

Random seed value.

Default: 1000

DiamondSquareFactor
property DiamondSquareFactor: Single read FDiamondSquareFactor write FDiamondSquareFactor;

Multiplication factor for diamond-square contribution.

Default: 1.0

Range: 0.0 = no diamond-square, higher = more influence

DiamondSquareEnabled
property DiamondSquareEnabled: Boolean read FDiamondSquareEnabled write FDiamondSquareEnabled;

Enable/disable diamond-square processing.

Default: True


TPerlinNoiseTerrain

Generates smooth terrain using Perlin noise with configurable interpolation.

Inheritance: TDiamondSquareBasedTerrain → TPerlinNoiseTerrain

Properties

Intensity
property Intensity: Single read FIntensity write FIntensity;

Controls height intensity of noise. Higher = taller peaks.

Default: 0.25

Interpolation
property Interpolation: TPerlinNoiseInterpolation read FInterpolation write FInterpolation;

Interpolation method for smoothing.

Values:

  • TPerlinNoiseInterpolation.Linear - Fast, sharp
  • TPerlinNoiseInterpolation.Cosine - Smooth, natural (default)
  • TPerlinNoiseInterpolation.Cubic - Very smooth, slower

Default: Cosine

Example

var
  LAlg: TPerlinNoiseTerrain;
begin
  LAlg := TPerlinNoiseTerrain.Create;
  try
    LAlg.Size := 8;
    LAlg.Intensity := 0.4;
    LAlg.Interpolation := TPerlinNoiseInterpolation.Cosine;
    LAlg.DiamondSquareFactor := 0.6;
    LAlg.DiamondSquareEnabled := True;
    LTerrain.RandomTerrain(LAlg);
  finally
    LAlg.Free;
  end;
end;

TPlateauTerrain

Creates high flat plateaus surrounded by lower terrain.

Inheritance: TDiamondSquareTerrain → TPlateauTerrain

Properties

Plateaus
property Plateaus: Integer read FPlateaus write FPlateaus;

Number of plateaus to generate. May overlap due to random placement.

Default: 3

MinSize
property MinSize: Integer read FMinSize write FMinSize;

Minimum plateau radius in pixels.

Default: 50

MaxSize
property MaxSize: Integer read FMaxSize write FMaxSize;

Maximum plateau radius in pixels.

Default: 250

MinHeight
property MinHeight: Single read FMinHeight write FMinHeight;

Minimum height factor for plateaus.

Default: 0.25

Range: 0.0 to 1.0

MaxHeight
property MaxHeight: Single read FMaxHeight write FMaxHeight;

Maximum height factor for plateaus.

Default: 1.0

Range: 0.0 to 1.0

Inverted
property Inverted: Boolean read FInverted write FInverted;

When True, creates flat lowlands instead of plateaus.

Default: False

Example

var
  LAlg: TPlateauTerrain;
begin
  LAlg := TPlateauTerrain.Create;
  try
    LAlg.Size := 9;
    LAlg.Plateaus := 5;
    LAlg.MinSize := 80;
    LAlg.MaxSize := 300;
    LAlg.MinHeight := 0.5;
    LAlg.MaxHeight := 0.9;
    LAlg.Inverted := False;
    LTerrain.RandomTerrain(LAlg);
  finally
    LAlg.Free;
  end;
end;

TBrownianTerrain

Generates terrain using Brownian motion particle simulation.

Inheritance: TDiamondSquareBasedTerrain → TBrownianTerrain

Properties

Particles
property Particles: Integer read FParticles write FParticles;

Number of particles for simulation. More = more detail but slower.

Default: 3000

MinHeight
property MinHeight: Single read FMinHeight write FMinHeight;

Minimum height factor for computed peaks.

Default: 0.01

MaxHeight
property MaxHeight: Single read FMaxHeight write FMaxHeight;

Maximum height factor for computed peaks.

Default: 0.05

Example

var
  LAlg: TBrownianTerrain;
begin
  LAlg := TBrownianTerrain.Create;
  try
    LAlg.Size := 9;
    LAlg.Particles := 5000;
    LAlg.MinHeight := 0.02;
    LAlg.MaxHeight := 0.08;
    LAlg.DiamondSquareFactor := 0.3;
    LTerrain.RandomTerrain(LAlg);
  finally
    LAlg.Free;
  end;
end;

TPlanarTerrain

Generates completely flat terrain.

Inheritance: TRandomTerrainAlgorithm → TPlanarTerrain

Remarks: Useful as starting point for custom terrain modification. Generates 32×32 grid by default.

Example

LTerrain.RandomTerrain(TRandomTerrainAlgorithmType.Planar);

Algorithm Comparison

Algorithm Characteristics Best For Performance
Hill Smooth, rounded hills Gentle landscapes, valleys Fast
DiamondSquare Realistic peaks and valleys General terrain, mountains Medium
Mandelbrot Fixed fractal pattern Artistic, alien landscapes Fast
PerlinNoise Natural, organic smoothness Realistic terrain, rolling hills Medium
Plateau Flat elevated areas Mesa terrain, plateaus Medium
Brownian Particle-based randomness Rough, chaotic terrain Slow
Planar Completely flat Testing, custom base Very Fast

See Also