GeoGen Script reference
Example: Conflux

This script creates a map with several rivers meeting in a central lake.


The map is finite in both the horizontal and vertical directions. This script declares two script parameters - one is numeric and can configure number of rivers meeting in the conflux and the other configures size of the central lake.

enum LakeSizes
Width: Finite,
Height: Finite,
Name: "Conflux",
Description: "Several rivers meeting in a central lake.",
Author: "Matěj Zábský",
LakeSize: { Type: LakeSizes, Default: Medium },
NumberOfRivers: { Min: 2, Max: 16, Default: 6 }
([500, 500], 500, 0.5, 0);
var noise = HeightMap.Noise();
yield map;

The basic idea is to create a template out of lines and a circle, distort it, turn it into a three-dimensional shape with HeightMap.Distance map and then sprinkle in some noise to make the map look more natural.

First step to create the template is to draw lines going from center of the map to points on a circle greater than the map itself (so that end of the lines is never seen). Spacing of the points on the circle is slightly randomized, to make the map less predictable.

A circle with radius based on the LakeSize script parameter is then added to the template.

Because the whole template is to be used with HeightMap.DistanceMap, the "base" height is 1 (any height greater than 0 would suffice) and the highlight height is any height equal to or less than 0.

var template = HeightMap.Flat(1);
// Draw the star from lines
var angleStep = 360 / Parameters.NumberOfRivers;
var startingAngle = Random(0, 360);
for(var angle = startingAngle; angle < startingAngle + 360; angle += angleStep)
var maximumAngleDeviation = angleStep / 4;
var randomizedAngle = Random(angle - maximumAngleDeviation, angle + maximumAngleDeviation);
var point = @[
0.5 + Cos(DegToRad(randomizedAngle)),
0.5 + Sin(DegToRad(randomizedAngle))];
template.DrawLine(@[0.5, 0.5], point, -1);
//template.Intersect(HeightMap.RadialGradient(@[0.5, 0.5], Number.FromEnum(Parameters.LakeSize) * 50, -1, 1));

The template is then distorted. The distortion is always continuous, guaranteed not to break the lines.

template.Distort(100, 50);
template.Distort(50, 25);

The distortion however causes the lines and shapes to blur, which can be rectified by sharpening the image. HeightMap.CropHeights can be used for this purpose. Using the same number as both its min and max arguments will replace all height but that height with replace. In this case, all heights other than 1 are replaced with 0.

template.CropHeights(1, 1, 0);

The template is now finished and can be used for the distance map. A small number is subtracted from the distance map to create basins of the rivers and the lake.

var distanceMap = HeightMap.DistanceMap(template, 100)
distanceMap.Add(HeightMap.RadialGradient(@[0.5, 0.5], 700, -1, 1));

The lowland and the highland are then combined together using a copy of the distance map as a mask.


The final step is to apply a glaciation filter on the map, making the river banks much softer.


Full code