Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Preparing for hackage release

  • Loading branch information...
commit d931c45134f22a37bd2d941409dfb1ac46cfbff9 1 parent ddc78b3
@colinhect authored
Showing with 50 additions and 6 deletions.
  1. +35 −0 examples/Perlin.hs
  2. +15 −6 hsnoise.cabal
View
35 examples/Perlin.hs
@@ -0,0 +1,35 @@
+module Perlin where
+
+import Noise.Perlin
+
+import Codec.PPM.Binary
+import Data.Word
+
+main = do
+ -- The size of the resulting image.
+ let size = 200
+
+ -- Parameters for the noise function.
+ let seed = 1
+ let octaves = 5
+ let scale = 0.05
+ let persistance = 0.5
+
+ -- Create the perlin function.
+ let perlin = Perlin seed octaves scale persistance
+
+ -- Compute the noise value for each pixel in the image.
+ let coords = [1.0..fromInteger size]
+ let xs = [noiseValue perlin (x, y, 0) | y <- coords, x <- coords]
+
+ -- Convert the noise values to grayscale colors.
+ let ps = map noiseToColor xs
+
+ -- Write the image.
+ writePPM "Noise.ppm" (size, size) ps
+ return ()
+
+-- Converts a value from -1 to 1 to a gray 24-bit color value from 0 to 255.
+noiseToColor :: Double -> (Word8, Word8, Word8)
+noiseToColor n = (n', n', n')
+ where n' = fromInteger (floor ((n * 0.5 + 0.5) * 255)) :: Word8
View
21 hsnoise.cabal
@@ -6,25 +6,34 @@ build-type: Simple
license: BSD3
license-file: LICENSE
-copyright: Copyright 2011, Colin Hill
+copyright: Copyright (c) 2011, Colin Hill
author: Colin Hill <colin.james.hill@gmail.com>
maintainer: Colin Hill <colin.james.hill@gmail.com>
stability: Experimental
-homepage:
+homepage: <https://github.com/colinhect/hsnoise>
synopsis: A coherent 3d noise library.
-description: .
-
+
+description: A coherent 3d noise library loosely based on libnoise. Currently has an
+ implementation of perlin noise. Will eventually support other noise
+ types as well as noise function combinations.
+ .
+ Code examples included in package.
+ .
+ Example of Perlin noise output image: <http://i.imgur.com/cPOZ2.png>
+ .
+
category: Noise
+extra-source-files: examples/Perlin.hs
+
library
exposed-modules:
Noise
Noise.Perlin
Noise.Random
- build-depends: AC-PPM -any, base -any, vector -any
+ build-depends: AC-PPM -any, base >= 2 && < 4, vector -any
ghc-options: -O2
hs-source-dirs: src
-
Please sign in to comment.
Something went wrong with that request. Please try again.