GeoGen Script reference
Contructors | Member Functions
HeightProfile Class Reference

One-dimensional height profile. More...

Contructors

static HeightProfile Clone (HeightProfile heightProfile)
 Creates a deep copy of another height profile. More...
 
static HeightProfile Flat (Number height)
 Creates a height profile with constant height. More...
 
static HeightProfile FromArray (Array array, Direction direction)
 Creates a profile from an array of pairs coordinate-height. More...
 
static HeightProfile Gradient (Coordinate sourceCoordinate, Coordinate destinationCoordinate, Number sourceHeight, Number destinationHeight)
 Creates a linear height gradient going from sourceHeight at source to destinationHeight at destination. More...
 
static HeightProfile Noise (Array layerDefinitions, Number seed)
 Creates a height profile filled with random perlin noise. More...
 
static HeightProfile Pattern (HeightProfile pattern, Coordinate intervalStart, Coordinate intervalEnd)
 Creates a height profile with an interval of pattern repeating infinitely in both directions. More...
 
static HeightProfile Slice (HeightMap heightMap, Number coordinate, Direction direction)
 Creates a height profile from a single row (if direction is horizontal) or column (if direction is vertical) of pixels of an height map. More...
 

Member Functions

HeightProfile Abs ()
 Replaces height in each pixel with its absolute value (makes negative heights positive). More...
 
HeightProfile Add (Number/HeightProfile addend, HeightProfile mask)
 Adds a number or a corresponding pixel from another height profile to each pixel in the height profile. More...
 
HeightProfile Blur (Number radius)
 Blurs the height profile with box blur algorithm with kernel of given radius. More...
 
HeightProfile ClampHeights (Number min, Number max)
 Replaces heights greater than max with max and less than min with min. More...
 
HeightProfile Combine (HeightProfile other, HeightProfile mask)
 Replaces heights in each pixel with a height blended from that height and corresponding height from another height profile. More...
 
HeightProfile Crop (Coordinate intervalStart, Coordinate intervalEnd, Number replace)
 Replaces all heights outside of an interval with replace. More...
 
HeightProfile CropHeights (Number min, Number max, Number replace)
 Replaces heights greater than max or less than min with replace. More...
 
HeightProfile Fill (Number height)
 Replaces each pixel with height. More...
 
HeightProfile FillInterval (Coordinate intervalStart, Coordiante intervalEnd, Number height)
 Replaces each pixel in an interval with height. More...
 
HeightProfile Fill ()
 Flips the profile around coordinate 0. More...
 
HeightProfile Intersect (HeightProfile other)
 Sets each pixel in the to the less of the two corresponding heights in the current profile and the other profile. More...
 
HeightProfile Invert ()
 Flips sign of each height in the profile. More...
 
HeightProfile Move (Point offset)
 Moves the height profile by offset. More...
 
HeightProfile Multiply (Number/HeightProfile factor)
 Multiplies the height in each pixel by a number or a corresponding pixel from another height profile. More...
 
HeightMap Rescale (Number scale)
 Enlarges (with scale > 1) or shrinks (with scale < 1) the entire profile. More...
 
HeightProfile Unify (HeightProfile other)
 Sets each pixel in the to the greater of the two corresponding heights in the current profile and the other profile. More...
 

Detailed Description

One-dimensional height profile.

Coordinates go from left (negative) to right (positive).

Examples:
marshlands.ggs.

Member Function Documentation

HeightProfile HeightProfile.Abs ( )

Replaces height in each pixel with its absolute value (makes negative heights positive).

Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.Add ( Number/HeightProfile  addend,
HeightProfile  mask 
)

Adds a number or a corresponding pixel from another height profile to each pixel in the height profile.

If mask is provided, the addition in each pixel will be modulated by the mask. Heights less than 0 from the mask are considered to be 0.

Parameters
addendThe addend.
mask(Optional) The mask.
Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.Blur ( Number  radius)

Blurs the height profile with box blur algorithm with kernel of given radius.

See also
Box blur on Wikipedia
Parameters
radiusThe blur kernel size.
Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.ClampHeights ( Number  min,
Number  max 
)

Replaces heights greater than max with max and less than min with min.

Parameters
minThe minimum height.
maxThe maximum height.
Returns
The height profile itself (for call chaining).
static HeightProfile HeightProfile.Clone ( HeightProfile  heightProfile)
static

Creates a deep copy of another height profile.

Parameters
heightProfile(Optional) The profile to copy.
Returns
The height profile.
HeightProfile HeightProfile.Combine ( HeightProfile  other,
HeightProfile  mask 
)

Replaces heights in each pixel with a height blended from that height and corresponding height from another height profile.

The blending will be done according to the height in the mask - 1 will mean 100% of the current height profile's height will be used, 0 will mean 100% of the height from the other height profile will be used. Any heights in between will cause the two heights to be blended linearly. Heights less than 0 from the mask are considered to be 0.

Parameters
otherThe other profile.
maskThe mask.
Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.Crop ( Coordinate  intervalStart,
Coordinate  intervalEnd,
Number  replace 
)

Replaces all heights outside of an interval with replace.

Parameters
intervalStartThe position of start of the interval.
intervalEndThe position of end of the interval.
replace(Optional) The replacement height. 0 is used if not provided.
Returns
The height profile.
HeightProfile HeightProfile.CropHeights ( Number  min,
Number  max,
Number  replace 
)

Replaces heights greater than max or less than min with replace.

Parameters
minThe minimum height.
maxThe maximum height.
replace(Optional) The replacement height. 0 is used if not provided.
Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.Fill ( Number  height)

Replaces each pixel with height.

Parameters
heightThe height.
Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.Fill ( )

Flips the profile around coordinate 0.

Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.FillInterval ( Coordinate  intervalStart,
Coordiante  intervalEnd,
Number  height 
)

Replaces each pixel in an interval with height.

Parameters
intervalStartThe position of start of the interval.
intervalEndThe position of end of the interval.
heightThe height.
Returns
The height profile itself (for call chaining).
static HeightProfile HeightProfile.Flat ( Number  height)
static

Creates a height profile with constant height.

Parameters
height(Optional) The height. If not provided, 0 is used.
Returns
The height profile.
static HeightProfile HeightProfile.FromArray ( Array  array,
Direction  direction 
)
static

Creates a profile from an array of pairs coordinate-height.

In each pair, the key has to be a Coordinate (or be convertible to it) and height must be a Number. The array doesn't have to be in any particular order.

Heights between the array entries will be interpolated using the linear interpolation algorithm. Any pixels before the least coordinate in the array will be filled with that height (and any pixels beyond the greatest coordinate will also be filled with that's entry's height).

Example:

var array = {
600: 1,
400: -1,
200: 0.5
};
var profile = HeightProfile.FromArray(array);
std_1d_fromarray.png
Parameters
arrayThe array.
direction(Optional) Direction in which relative coordinates are resolved. Doesn't affect anything if no relative coordinates are used.
Returns
The height profile.
Examples:
marshlands.ggs.
static HeightProfile HeightProfile.Gradient ( Coordinate  sourceCoordinate,
Coordinate  destinationCoordinate,
Number  sourceHeight,
Number  destinationHeight 
)
static

Creates a linear height gradient going from sourceHeight at source to destinationHeight at destination.

Pixels outside of the gradient strip are filled with height of source or destination, whichever is closer.

Parameters
sourceCoordinateThe source coordinate.
destinationCoordinateThe destination coordinate.
sourceHeightHeight at the source.
destinationHeightHeight at the destination.
Returns
The height profile.
HeightProfile HeightProfile.Intersect ( HeightProfile  other)

Sets each pixel in the to the less of the two corresponding heights in the current profile and the other profile.

Parameters
otherThe other map.
Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.Invert ( )

Flips sign of each height in the profile.

Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.Move ( Point  offset)

Moves the height profile by offset.

Parameters
offsetThe offset. The map is offset to the right.
Returns
The height profile itself (for call chaining).
HeightProfile HeightProfile.Multiply ( Number/HeightProfile  factor)

Multiplies the height in each pixel by a number or a corresponding pixel from another height profile.

Parameters
factorThe factor.
Returns
A HeightProfile.
static HeightProfile HeightProfile.Noise ( Array  layerDefinitions,
Number  seed 
)
static

Creates a height profile filled with random perlin noise.

The layer definitions are an array of pairs wave length: amplitude. Wave length and amplitude must be greater than 0. Example:

var profile = HeightProfile.Noise({256: 1});
std_1d_noise_custom.png

The default value for layerDefinitions parameter is:

{
{1: 0.001953125},
{2: 0.00390625},
{4: 0.0078125},
{8: 0.015625},
{16: 0.03125},
{32: 0.0625},
{64: 0.125},
{128: 0.25},
{256: 0.5}
}

Which produces noise like this:

std_1d_noise_standard.png

TODO: Overshoots.

See also
Perlin noise
Parameters
layerDefinitions(Optional) Array defining layers of the noise. If not provided, a default array is used. This array can be created using CreateNoiseLayers.
seed(Optional) Random seed. If not provided, 0 is used. This seed is always combined with the main script seed provided in script arguments to the script.
Returns
The height profile.
Examples:
marshlands.ggs.
static HeightProfile HeightProfile.Pattern ( HeightProfile  pattern,
Coordinate  intervalStart,
Coordinate  intervalEnd 
)
static

Creates a height profile with an interval of pattern repeating infinitely in both directions.

The repeating pattern will start at coordinate 0.

Parameters
patternThe height profile from which the pattern is copied.
intervalStartThe position of start of the interval.
intervalEndThe position of end of the interval.
Returns
The height profile.
HeightMap HeightProfile.Rescale ( Number  scale)

Enlarges (with scale > 1) or shrinks (with scale < 1) the entire profile.

The scaling transformation has origin at coordiante 0. Uses linear interpolation.

Parameters
scaleThe scale ratio. Must be greater than 0.1 and less than 10.
Returns
The height profile itself (for call chaining).
static HeightProfile HeightProfile.Slice ( HeightMap  heightMap,
Number  coordinate,
Direction  direction 
)
static

Creates a height profile from a single row (if direction is horizontal) or column (if direction is vertical) of pixels of an height map.

Parameters
heightMapThe height map to create the slice from.
coordinateCoordinate of the row/column.
directionThe projection direction.
Returns
The height profile.
HeightProfile HeightProfile.Unify ( HeightProfile  other)

Sets each pixel in the to the greater of the two corresponding heights in the current profile and the other profile.

Parameters
otherThe other profile.
Returns
The height profile itself (for call chaining).