实现基础的 Simplex Noise 算法
moon add ZSeanYves/SimplexNoise"import": ["ZSeanYves/SimplexNoise"]let config = @ZSeanYves/SimplexNoise.new_NoiseConfig(6, 0.5, 2.0, 0.03)
let (_, grads) = @ZSeanYves/SimplexNoise.create2d(42)
@ZSeanYves/SimplexNoise.fbm2d_image("./fbm2d.png", 256, 256, 42, grads, config, true, false, strength~ = 2.5)let config = new_NoiseConfig(5, 0.5, 2.0, 0.03)
let (_, grads) = create3d(99)
@ZSeanYves/SimplexNoise.tfbm3d_image("./tile3d.png", 256, 256, 64, 99, 0.0, grads, config, pi~ = 3.14, true)let config = new_NoiseConfig(4, 0.5, 2.0, 0.03)
let (_, grads) = create4d(123)
@ZSeanYves/SimplexNoise.fbm4d_slices("./slices", 128, 128, 64, 123, grads, config, false, true, 10)| Function | Dim | Type | Tileable | Warp | Slice | Output |
|---|---|---|---|---|---|---|
| noise2d_image | 2D | basic | ❌ | ✅ | ❌ | PNG |
| fbm2d_image | 2D | fBm | ❌ | ✅ | ❌ | PNG |
| tnoise2d_image | 2D | basic | ✅ | ❌ | ❌ | PNG |
| tfbm2d_image | 2D | fBm | ✅ | ❌ | ❌ | PNG |
| noise3d_image | 3D | basic | ❌ | ✅ | ❌ | PNG |
| fbm3d_image | 3D | fBm | ❌ | ✅ | ❌ | PNG |
| tnoise3d_image | 3D | basic | ✅ | ❌ | ❌ | PNG |
| tfbm3d_image | 3D | fBm | ✅ | ❌ | ❌ | PNG |
| noise3d_slices | 3D | basic | ❌ | ✅ | ✅ | PNG |
| fbm3d_slices | 3D | fBm | ❌ | ✅ | ✅ | PNG |
| noise4d_image | 4D | basic | ❌ | ✅ | ❌ | PNG |
| fbm4d_image | 4D | fBm | ❌ | ✅ | ❌ | PNG |
| tnoise4d_image | 4D | basic | ✅ | ❌ | ❌ | PNG |
| tfbm4d_image | 4D | fBm | ✅ | ❌ | ❌ | PNG |
| noise4d_slices | 4D | basic | ❌ | ✅ | ✅ | PNG |
| fbm4d_slices | 4D | fBm | ❌ | ✅ | ✅ | PNG |
| Parameter | Description |
|---|---|
| width, height | Output image size in pixels |
| depth, time | For 3D/4D tileable output |
| scale | Controls frequency of noise |
| seed | Determines permutation table |
| grads | Gradient vector table |
| z, w | Slice positions in 3D/4D |
| pi~ | Controls tileability (default 3.14) |
| strength~ | Warp intensity (default 1.0) |
| useWarp | Enable domain warping |
| isGrayScale | Use grayscale or RGB |
SimplexNoise/
├── src/
│ ├── noise2d.mbt / noise3d.mbt / noise4d.mbt # Core simplex noise
│ ├── fbm.mbt / fbm3d.mbt / fbm4d.mbt # fBm logic
│ ├── image_gen.mbt / slice.mbt # PNG output & slicing
│ ├── simplex_noise.mbt / SimplexNoise.mbti # Public interface
│ ├── hash.mbt # build hash
│ └── simplex_noise_test.mbt # Full test suite
├── examples/ # Output images
├── moon.pkg.json / LICENSE / README.mdmoon test -p ZSeanYves/SimplexNoisepub struct NoiseConfig {
octaves : Int
persistence : Float
lacunarity : Float
scale : Float
}fn fbm2d_image(path : String, width : Int, height : Int, seed : Int, grads : Array[Array[Float]], config : NoiseConfig, useWarp : Bool, isGrayScale : Bool, strength~ : Float = ..) -> Bool raise Errorfn fbm3d_image(path : String, width : Int, height : Int, z : Float, seed : Int, grads : Array[Array[Float]], config : NoiseConfig, useWarp : Bool, isGrayScale : Bool, strength~ : Float = ..) -> Bool raise Errorfn fbm3d_slices(base_path : String, width : Int, height : Int, seed : Int, grads : Array[Array[Float]], config : NoiseConfig, useWarp : Bool, isGrayScale : Bool, strength~ : Float = .., slice_count : Int) -> Unit raise Errorfn fbm4d_image(path : String, width : Int, height : Int, z : Float, w : Float, seed : Int, grads : Array[Array[Float]], config : NoiseConfig, useWarp : Bool, isGrayScale : Bool, strength~ : Float = ..) -> Bool raise Errorfn fbm4d_slices(base_path : String, width : Int, height : Int, z : Float, seed : Int, grads : Array[Array[Float]], config : NoiseConfig, useWarp : Bool, isGrayScale : Bool, strength~ : Float = .., slice_count : Int) -> Unit raise Errorfn new_NoiseConfig(octaves : Int, persistence : Float, lacunarity : Float, scale : Float) -> NoiseConfigfn tfbm2d_image(path : String, width : Int, height : Int, seed : Int, grads : Array[Array[Float]], config : NoiseConfig, pi~ : Double = .., isGrayScale : Bool) -> Bool raise Errorfn tfbm3d_image(path : String, width : Int, height : Int, depth : Int, seed : Int, z : Float, grads : Array[Array[Float]], config : NoiseConfig, pi~ : Double = .., isGrayScale : Bool) -> Bool raise Errorfn tfbm4d_image(path : String, width : Int, height : Int, depth : Int, time : Int, z : Float, w : Float, seed : Int, grads : Array[Array[Float]], config : NoiseConfig, pi~ : Double = .., isGrayScale : Bool) -> Bool raise Error