0 people like it.

worley-noise

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
module WorleyNoise
open System
open System.Collections.Generic

let worleyNoise width height pointCount seed (distanceFn : int * int -> int * int -> int) combinationFn =
    let cells = Array2D.create width height 0
    let prng = new Random(seed)
    let points = Array.init pointCount (fun _ -> prng.Next(width), prng.Next(height))
    for x in 0 .. width - 1 do
        for y in 0 .. height - 1 do
            cells.[x, y] <- Array.map (distanceFn (x, y)) points |> Array.sort |> combinationFn
    cells
module WorleyNoise
namespace System
namespace System.Collections
namespace System.Collections.Generic
val worleyNoise : width:int -> height:int -> pointCount:int -> seed:int -> distanceFn:(int * int -> int * int -> int) -> combinationFn:(int [] -> int) -> int [,]

Full name: WorleyNoise.worleyNoise
val width : int
val height : int
val pointCount : int
val seed : int
val distanceFn : (int * int -> int * int -> int)
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val combinationFn : (int [] -> int)
val cells : int [,]
module Array2D

from Microsoft.FSharp.Collections
val create : length1:int -> length2:int -> value:'T -> 'T [,]

Full name: Microsoft.FSharp.Collections.Array2D.create
val prng : Random
Multiple items
type Random =
  new : unit -> Random + 1 overload
  member Next : unit -> int + 2 overloads
  member NextBytes : buffer:byte[] -> unit
  member NextDouble : unit -> float

Full name: System.Random

--------------------
Random() : unit
Random(Seed: int) : unit
val points : (int * int) []
type Array =
  member Clone : unit -> obj
  member CopyTo : array:Array * index:int -> unit + 1 overload
  member GetEnumerator : unit -> IEnumerator
  member GetLength : dimension:int -> int
  member GetLongLength : dimension:int -> int64
  member GetLowerBound : dimension:int -> int
  member GetUpperBound : dimension:int -> int
  member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
  member Initialize : unit -> unit
  member IsFixedSize : bool
  ...

Full name: System.Array
val init : count:int -> initializer:(int -> 'T) -> 'T []

Full name: Microsoft.FSharp.Collections.Array.init
Random.Next() : int
Random.Next(maxValue: int) : int
Random.Next(minValue: int, maxValue: int) : int
val x : int32
val y : int32
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
val sort : array:'T [] -> 'T [] (requires comparison)

Full name: Microsoft.FSharp.Collections.Array.sort
Raw view Test code New version

More information

Link:http://fssnip.net/9d
Posted:14 years ago
Author:
Tags: