Package eu.svjatoslav.sixth.e3d.math
Class DiamondSquare
java.lang.Object
eu.svjatoslav.sixth.e3d.math.DiamondSquare
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 TypeMethodDescriptionstatic 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 booleanisValidGridSize(int size) Checks if the grid size is valid for the diamond-square algorithm.
-
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 outputmax- the maximum value in the outputseed- 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 outputmax- the maximum value in the outputroughness- the roughness factor (0.0 to 1.0), higher values produce more variationseed- 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
-