From f66771603d26d8953b574748b91d0ff035551816 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 27 May 2022 14:58:39 -0500 Subject: add basic terrain generation --- modules/Terrain.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 modules/Terrain.js (limited to 'modules/Terrain.js') diff --git a/modules/Terrain.js b/modules/Terrain.js new file mode 100644 index 0000000..ca0ab77 --- /dev/null +++ b/modules/Terrain.js @@ -0,0 +1,82 @@ +'use strict'; + +import Voronoi from './3rdparty/rhill-voronoi-core.js'; + +import { useAverage } from './Util.js'; +import { QuadTree } from './Geometry.js'; + + +/* from here on up, we always assume that points live in the range [(0,0), (1,1)) */ + +function lloydRelax(point_set, density) { + /* setup quadtree and averages */ + let tree = new QuadTree(1,1); + let averages = {}; + for (let i=0; i ({x: Math.random(), y: Math.random()}); + + let seed_points = []; + for (let i=0; i