From aa8c3128db15bdadf241fd36d275bb0109158cbf Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Fri, 25 Feb 2022 21:33:51 +0800 Subject: [PATCH] tweak world generation --- internal/world/worldgen/worldgen.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/world/worldgen/worldgen.go b/internal/world/worldgen/worldgen.go index 48863b5..20780ec 100644 --- a/internal/world/worldgen/worldgen.go +++ b/internal/world/worldgen/worldgen.go @@ -27,6 +27,18 @@ func init() { perlins = make(map[int64]*perlin.Perlin) } +func fractal(p *perlin.Perlin, x, y float64, levels int) float64 { + ans := 0.0 + amp := 1.0 + for i := 0; i < levels; i++ { + ans += amp * p.Noise2D(x, y) + amp /= 3 + x *= 2 + y *= 2 + } + return ans +} + // Chunk generates the chunk (must with chunkID set!!) with seed. func Chunk(chunk *packworld.Chunk, world *packworld.World, seed int64) { @@ -50,9 +62,10 @@ func Chunk(chunk *packworld.Chunk, world *packworld.World, seed int64) { for x := 0; x < packworld.ChunkSizeX; x++ { for z := 0; z < packworld.ChunkSizeZ; z++ { - height := Lowest + int(float64(Highest-Lowest)*(p.Noise2D( + height := Lowest + int(float64(Highest-Lowest)*(fractal( + p, float64(offX+x)/AltitudeDensity, - float64(offZ+z)/AltitudeDensity)/2+0.5)) + float64(offZ+z)/AltitudeDensity, 6)/2+0.5)) //log.Printf("height = %d (noise=%.5f)", height, p.Noise2D(float64(offX+x)/AltitudeDensity, float64(offZ+z)/AltitudeDensity)/2+0.5) // water