Class DiamondSquare

java.lang.Object
eu.svjatoslav.sixth.e3d.math.DiamondSquare

public final class DiamondSquare extends Object
Diamond-square algorithm for procedural noise generation.

Generates realistic fractal noise suitable for terrain, textures, and other procedural content. The algorithm produces a 2D map where each value falls within the specified [min, max] range.

Grid size must be 2^n + 1 (e.g., 3, 5, 9, 17, 33, 65, 129, 257).

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[][]
    generateMap(int gridSize, double min, double max, double roughness, long seed)
    Generates a fractal noise map using the diamond-square algorithm with custom roughness.
    static double[][]
    generateMap(int gridSize, double min, double max, long seed)
    Generates a fractal noise map using the diamond-square algorithm.
    static boolean
    isValidGridSize(int size)
    Checks if the grid size is valid for the diamond-square algorithm.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • generateMap

      public static double[][] generateMap(int gridSize, double min, double max, long seed)
      Generates a fractal noise map using the diamond-square algorithm.
      Parameters:
      gridSize - the size of the grid (must be 2^n + 1)
      min - the minimum value in the output
      max - the maximum value in the output
      seed - random seed for reproducible results
      Returns:
      a 2D array of values in range [min, max]
      Throws:
      IllegalArgumentException - if gridSize is not 2^n + 1
    • generateMap

      public static double[][] generateMap(int gridSize, double min, double max, double roughness, long seed)
      Generates a fractal noise map using the diamond-square algorithm with custom roughness.
      Parameters:
      gridSize - the size of the grid (must be 2^n + 1)
      min - the minimum value in the output
      max - the maximum value in the output
      roughness - the roughness factor (0.0 to 1.0), higher values produce more variation
      seed - random seed for reproducible results
      Returns:
      a 2D array of values in range [min, max]
      Throws:
      IllegalArgumentException - if gridSize is not 2^n + 1
    • isValidGridSize

      public static boolean isValidGridSize(int size)
      Checks if the grid size is valid for the diamond-square algorithm. Valid sizes are 2^n + 1 (e.g., 3, 5, 9, 17, 33, 65, 129, 257).
      Parameters:
      size - the grid size to validate
      Returns:
      true if the size is valid