tweak world generation

This commit is contained in:
Edgaru089 2022-02-25 21:33:51 +08:00
parent 08e08000a6
commit aa8c3128db

View File

@ -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