'use strict'; import Voronoi from './3rdparty/rhill-voronoi-core.js'; import { useAverage } from './modules/Util.js'; import { AABB, QuadTree } from './modules/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()}); this.min_height = 0; this.max_height = 0; let seed_points = []; for (let i=0; i (a.x - b.x)**2 + (a.y - b.y)**2; const sigma = radius/3; const beta = 1/(2*sigma*sigma); const center = { x, y }; const power = pt => Math.exp(-beta * dist2(pt, center)); for (let pt of points) f(pt, strength * power(pt)); } renderGrid(ct) { ct.save(); ct.lineWidth = 0.001; for (let edge of this.graph.edges) { ct.fillStyle = `hsl(${edge.va.hue}, 100%, 50%)`; ct.beginPath(); ct.arc(edge.va.x, edge.va.y, 0.005, 0, 2*Math.PI); ct.closePath(); ct.fill(); ct.beginPath(); ct.moveTo(edge.va.x, edge.va.y); ct.lineTo(edge.vb.x, edge.vb.y); ct.closePath(); ct.stroke(); } ct.restore(); } } export { lloydRelax }; export default Terrain;