genheightmap

package
v0.0.0-...-ce97658 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

README

genheightmap

This package provides various convenience functions to generate heightmaps. The functions in this package are used for example by genmapvoronoi for the heightmap generation.

Generation of landscape features:

  • Opensimplex noise
  • Slope
  • Cone
  • Volcano cone
  • Crater
  • Fissure
  • Mountains/Hills

Operations on heightmaps:

  • Normalization
  • Relaxing
  • Peakify (agitation / roughness)

alt text

alt text

alt text

alt text

alt text

TODO

  • Tidy up the code
  • User-defined offsets
  • User-defined seeds (or custom rand source)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcMean

func CalcMean(nums []float64) float64

CalcMean calculates the mean of a slice of floats.

func MinMax

func MinMax(hm []float64) (float64, float64)

MinMax returns the min and max values of the heightmap.

Types

type GenFunc

type GenFunc func(x, y float64) float64

func GenCone

func GenCone(slope float64) GenFunc

GenCone returns a generator function for a cone at the center of the heightmap. TODO: Allow the user to specify the center of the cone.

func GenCrater

func GenCrater(center vectors.Vec2, diameter, lip, depth float64) GenFunc

GenCrater modifies the height values in a circular region to create a crater with a lip.

func GenFissure

func GenFissure(p1, p2 vectors.Vec2, steps int, lip, drop, amplitude, width float64, useNormalVecs bool) GenFunc

GenFissure returns a generator function that produces a fissure between two points on the heightmap, with the given increase in height at the lips and the drop in elevation at the base of the fissure.

NOTE: We use a biased random walk to generate the fissure path using the given points as the starting and ending points of the walk, and the given number of steps as the number of steps in the walk, as well as the amplitude of the walk and the width of the fissure.

UseNormalVecs determines whether we use the normal vector of the path to generate the path of the fissure, or if we use a random vector.

func GenMountainRange

func GenMountainRange(p1, p2 vectors.Vec2, steps int, radius, amplitude, maxHeight float64, useNormalVecs bool) GenFunc

GenMountainRange returns a generator function that produces a mountain range between the two given points, with the given number of peaks (or steps), the given radius of the mountains, and the given amplitude of the variation in the mountain range and a maximum height of the mountains

NOTE: We use a biased random walk to generate the mountain range using the given points as the starting and ending points of the walk, and the given number of steps as the number of steps in the walk, as well as the amplitude of the walk and the radius of the mountains.

UseNormalVecs determines whether we use the normal vector of the path to generate the path of the mountain range, or if we use a random vector.

func GenMountains

func GenMountains(maxX, maxY float64, n int, r float64) GenFunc

GenMountains returns a generator function that will return the height of a point on the heightmap given the point's coordinates, which will produce a number of mountains. TODO: The seed should be passed into the function as parameter.

'maxX', 'maxY' are the dimensions of the heightmap. 'n' is the number of mountains. 'r' is the radius of the mountains.

func GenNoise

func GenNoise(seed int64, slope float64) GenFunc

GenNoise returns a function that returns the noise/height value of a given point on the heightmap. Not sure what the slope parameter was supposed to do.

func GenSlope

func GenSlope(direction vectors.Vec2) GenFunc

GenSlope returns a generator function that produces a slope in the direction of the given vector.

func GenVolCone

func GenVolCone(slope float64) GenFunc

GenVolCone returns a generator function for a volcanic cone at the center of the heightmap. TODO: Allow the user to specify the center of the cone.

type GetHeight

type GetHeight func(idx int) float64

GetHeight returns the height of a point on the heightmap given its index.

type GetNeighbors

type GetNeighbors func(idx int) []int

GetNeighbors returns all neighbor indices of an index on the heightmap.

type Modify

type Modify func(val float64) float64

Modify is a function that modifies a value in a heightmap.

func ModNormalize

func ModNormalize(min, max float64) Modify

ModNormalize normalizes the heightmap to the range [0, 1] given the min and max values (the range of heightmap values).

func ModPeaky

func ModPeaky() Modify

ModPeaky returns the function applied to a point on a heightmap in order to exaggerate the peaks of the map.

func ModSeaLevel

func ModSeaLevel(min, max, q float64) Modify

ModSeaLevel shifts the origin point to the sea level, resulting in all points below sea level being negative.

type ModifyWithIndex

type ModifyWithIndex func(idx int, val float64) float64

ModifyWithIndex is a function that modifies a value in a heightmap given its index and current value.

func ModRelax

func ModRelax(n GetNeighbors, h GetHeight) ModifyWithIndex

ModRelax applies a relaxation algorithm to the heightmap.

type Terrain

type Terrain interface {
	//ApplyGen(f GenFunc)
	MinMax() (float64, float64)
}

Terrain is an interface for a heightmap. ... I can't remember if I use this somewhere.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL