Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters