generative-art-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Geometry.Algorithms.SimplexNoise

Description

Simplex noise functions in various dimensions.

Based on example Java code by Stefan Gustavson. Optimisations by Peter Eastman. Better rank ordering method for 4D by Stefan Gustavson in 2012.

This code was placed in the public domain by its original author, Stefan Gustavson. You may use it as you see fit, but attribution is appreciated.

(image code)

Expand
>>> :{
haddockRender "Geometry/Algorithms/SimplexNoise/simplex_noise.svg" 500 500 $ \(Vec2 w h) -> do
let (simplexNoiseColor, simplexNoiseVisibility) = runST $ MWC.withRng [] $ \gen -> do
        c <- simplex2 gen def
            { _simplexFrequency = 5/(2*w)
            }
        v <- simplex2 gen def
            { _simplexFrequency = 10/(2*w)
            }
        pure (c,v)
    cellSize = 5
    hexes = hexagonsInRange 30 hexZero
    fitToViewport = transformBoundingBox (map (hexagonPoly cellSize) hexes) (shrinkBoundingBox 10 [zero, Vec2 w h]) def
for_ hexes $ \hex -> do
    let polygon = hexagonPoly cellSize hex
        vec = toVec2 cellSize hex
        color = icefire (lerp (-1,1) (0,1) (simplexNoiseColor vec))
    sketch (transform fitToViewport (shrinkPolygon 1 polygon))
    setColor (color `withOpacity` (lerp (-1,1) (0,1) (simplexNoiseVisibility vec)))
    C.fillPreserve
    setColor (color `withOpacity` (lerp (-1,1) (1,0.2) (simplexNoiseVisibility vec)))
    C.stroke
:}
Generated file: size 1MB, crc32: 0x1e0dba00
Synopsis

Documentation

data SimplexParameters Source #

Named arguments for simplex1, simplex2, simplex3, simplex4.

Constructors

SimplexParameters 

Fields

simplex1 Source #

Arguments

:: PrimMonad st 
=> Gen (PrimState st)

To initialize the permutation table

-> SimplexParameters 
-> st (Double -> Double) 

One-dimensional simplex noise. See simplex2 for a code example.

simplex2 Source #

Arguments

:: PrimMonad st 
=> Gen (PrimState st)

To initialize the permutation table

-> SimplexParameters 
-> st (Vec2 -> Double) 

Two-dimensional simplex noise.

noiseFunction = runST $ do
    gen <- create
    simplex2 gen def
for_ [1..10] $ x ->
    for_ [1..10] $ y ->
        print (noiseFunction (Vec2 x y))

simplex3 Source #

Arguments

:: PrimMonad st 
=> Gen (PrimState st)

To initialize the permutation table

-> SimplexParameters 
-> st (Double -> Double -> Double -> Double)

\(\text{noise}(x,y,z)\)

Three-dimensional simplex noise. See simplex2 for a code example.

simplex4 Source #

Arguments

:: PrimMonad st 
=> Gen (PrimState st)

To initialize the permutation table

-> SimplexParameters 
-> st (Double -> Double -> Double -> Double -> Double)

\(\text{noise}(x,y,z,w)\)

Four-dimensional simplex noise. See simplex2 for a code example.