All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.almasb.fxgl.procedural.BiomeMapGenerator.kt Maven / Gradle / Ivy

There is a newer version: 21.1
Show newest version
/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB ([email protected]).
 * See LICENSE for details.
 */

package com.almasb.fxgl.procedural

import com.almasb.fxgl.core.math.FXGLMath
import com.almasb.fxgl.core.collection.grid.Cell
import com.almasb.fxgl.core.collection.grid.CellGenerator

/**
 *
 *
 * @author Almas Baimagambetov ([email protected])
 */
open class BiomeMapGenerator
@JvmOverloads constructor(
        val width: Int,
        val height: Int,
        var frequency: Double = 10.0) : CellGenerator {

    class BiomeData(x: Int, y: Int, var elevation: Double, var moisture: Double) : Cell(x, y)

    override fun apply(x: Int, y: Int): BiomeData {
        val nx = x * 1.0 / width - 0.5
        val ny = y * 1.0 / height - 0.5

        // https://github.com/AlmasB/FXGL/issues/473
        return BiomeData(x, y, FXGLMath.noise2D(frequency * nx, frequency * ny), FXGLMath.noise2D(frequency * nx, frequency * ny))
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy