Created
December 23, 2019 09:36
-
-
Save slawo-ch/891dc987fb9e3d4d1b212e3891bb364e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const heightMap2 = []; | |
for (let u = 0; u < mapSize; u++) { | |
for (let v = 0; v < mapSize; v++) { | |
const i = u * mapSize + v; | |
const cx = u - mapSize / 2; | |
const cy = v - mapSize / 2; | |
// skewed distance as input to chaos field calculation, | |
// scaled for smoothness over map distance | |
const d1 = distance(0.8 * cx, 1.3 * cy) * 0.022; | |
const d2 = distance(1.35 * cx, 0.45 * cy) * 0.022; | |
const s = Math.sin(d1); | |
const c = Math.cos(d2); | |
// height value between -2 and +2 | |
const h = s + c; | |
// height value between 0..1 | |
const normalized = (h + 2) / 4; | |
// height value between 0..127, integer | |
heightMap2[i] = Math.floor(normalized * 127); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment