perlin

Ruby-implementation of N-dimension Perlin noise.

Installation

gem install perlin_noise

ruby require 'perlin_noise'

Basic

### One-dimension ruby n1d = Perlin::Noise.new 1 0.step(100, 0.01) do |x| puts n1d[x] end

Two-dimension, three-dimension, or even more dimensions

```ruby n2d = Perlin::Noise.new 2 0.step(100, 0.01) do |x| 0.step(100, 0.01) do |y| puts n2d[x, y] end end

n3d = Perlin::Noise.new 3 n3d[rand, rand, rand]

n5d = Perlin::Noise.new 5 n5d[rand, rand, rand, rand, rand] ```

Options

### :interval A gradient noise repeats itself at certain interval. (Default interval is 256) You can change the interval of the noise generator but keep in mind that longer interval requires more pseudo-random gradient vectors to be maintained in memory.

ruby n3d = Perlin::Noise.new 3, :interval => 100 n3d[0.1, 0.2, 0.3] n3d[0.1, 0.2, 100.3]

Range of noise function

While the original algorithm outputs a number between -1.0 and 1.0, Perlin::Noise#[] manipulates this output and returns a number between 0.0 and 1.0 for ease of use. Thus, noise values at all of the integer lattice points should be 0.5, not 0.

Increasing the contrast

Even though the range of the noise function is from 0 to 1, you’ll rarely see a noise value close to either end, as most of the values are distributed around the center. You might want to apply S-shaped curve functions defined in Perlin::Curve module one or more times to push away those numbers to either end.

```ruby noise = Perlin::Noise.new 1

n = noise[0.1]

3.times do n = Perlin::Curve::CUBIC.call n end ```

There’s a shortcut for this process. ruby contrast = Perlin::Curve.contrast(Perlin::Curve::CUBIC, 3) n = contrast.call n

1D noise

ruby noise = Perlin::Noise.new 1, :interval => 200 0.step(300, 0.1).each do |x| n = noise[x] len = (n * 60).to_i puts '#' * len end

############################## ################################ ################################## ################################## ################################ ############################## ########################### ######################### ######################### ########################### ############################## ################################# ##################################### ######################################## ########################################### ############################################# ########################################### ######################################## ##################################### ################################# ############################## ########################### ######################### ######################### ########################### ############################## ################################ ################################## ################################## ################################ ############################## ########################## ###################### ################### ################ ############### ################ ################### ###################### ########################## ############################## ################################# ##################################### ######################################## ########################################### ############################################# ########################################### ######################################## ##################################### ################################# ############################## ########################## ###################### ################### ################ ############### ################ ################### ###################### ########################## ############################## ################################# ##################################### ######################################## ########################################### ############################################# ########################################### ######################################## ##################################### ################################# ############################## ########################## ###################### ################### ################ ############### ################ ################### ###################### ########################## ############################## ################################ ################################## ################################## ################################ ############################## ########################### ######################### ######################### ########################### ############################## ################################# ##################################### ######################################## ########################################### ############################################# ########################################### ######################################## ##################################### ################################# ############################## ########################### ######################### ######################### ########################### ############################## ################################ ################################## ################################## ################################ ############################## ########################## ###################### ################### ################ ############### ################ ################### ###################### ########################## ############################## ################################# ##################################### ######################################## ########################################### ############################################# ########################################### ######################################## ##################################### ################################# ############################## ########################## ###################### ################### ################

2D noise

```ruby noises = Perlin::Noise.new(2) contrast = Perlin::Curve.contrast(Perlin::Curve::CUBIC, 2)

bars = “ ▁▂▃▄▅▆▇█”.each_char.to_a bar = lambda { |n| bars[ (bars.length * n).floor ] }

0.upto(100) do |i| 70.times do |y| n = noises[i * 0.1, y * 0.1] n = contrast.call n

print bar.call(n)   end   puts end ```

▃▃▂▂▁▁▁▁▂▃▃▄▅▅▆▆▆▅▅▅▅▅▅▄▄▃▃▂▂▃▃▄▄▄▄▄▄▄▄▄▅▅▆▇▇▇▇▇▆▅▄▃▂▁ ▁▂▃▄▅▆▆▇▇▆▆▅▅ ▂▂▁▁▁▁▁▁▂▂▃▄▄▅▆▆▆▆▆▆▆▆▆▅▅▄▃▂▂▂▃▃▄▄▄▄▄▅▅▅▆▆▇▇██▇▇▆▅▄▃▂▁ ▁▂▃▄▅▆▆▇▇▇▇▆▆ ▁▁▁▁▁▁▁▁▂▃▃▄▄▅▅▆▆▆▇▇▇▇▇▆▆▅▄▃▃▃▃▃▄▄▄▅▅▆▆▆▇▇▇███▇▇▆▅▄▃▂▁ ▁▁▂▃▄▅▆▇▇▇▇▇▇ ▁ ▁▁▁▂▂▃▃▃▄▄▅▅▆▆▇▇▇▇▇▇▇▇▆▅▄▃▃▃▄▄▄▅▆▆▇▇▇▇▇████▇▇▆▆▅▄▃▂▁ ▁▁▂▂▃▄▅▆▇████ ▁▁▁▂▃▃▄▄▄▄▄▄▅▅▆▆▇▇▇███▇▇▆▅▄▄▄▄▄▅▅▆▇▇▇▇▇▇████▇▇▇▆▅▅▄▂▁▁▁▁▁▁▂▃▄▅▆▇████ ▁▁▁▂▃▄▄▅▅▅▅▄▄▄▄▄▅▅▆▇▇▇███▇▇▆▅▅▅▅▅▅▆▆▇▇▇▇▇▇▇▇▇▇▇▇▇▆▆▅▄▃▂▁▁▁▁▁▂▂▃▄▆▇▇███ ▁▁▂▃▄▅▆▆▆▅▅▅▄▃▃▃▃▄▅▆▇▇▇███▇▇▆▆▅▅▅▅▆▆▇▇▇▇▇▆▆▆▆▆▇▇▆▆▆▅▅▄▃▂▁▁▁▁▂▂▃▄▅▆▇▇▇▇ ▂▃▃▄▅▆▇▆▆▆▅▄▄▃▂▂▂▃▄▅▆▆▇▇██▇▇▆▆▅▅▅▅▅▆▆▆▇▆▆▅▅▅▅▅▆▆▆▆▆▅▄▄▃▂▂▂▂▂▂▃▃▄▅▆▆▇▇▆ ▃▄▅▅▆▇▇▇▆▅▅▄▃▂▁▁▁▂▃▄▅▅▆▇▇▇▇▇▆▅▅▄▄▄▅▅▆▆▆▅▅▄▄▄▄▄▅▅▅▅▅▄▄▃▃▂▂▂▂▃▃▃▄▅▅▆▆▆▆▅ ▄▅▅▆▇▇▇▆▆▅▄▃▂▂▁▁▁▁▂▃▄▅▆▆▇▇▇▆▅▅▄▄▃▄▄▄▅▅▅▅▄▃▃▃▃▃▄▄▄▄▄▄▃▃▂▂▂▃▃▄▄▄▅▅▅▆▅▅▅▄ ▅▅▆▇▇▇▆▆▅▄▃▃▂▁▁ ▁▁▂▃▃▄▅▆▆▆▆▅▄▄▃▃▂▃▃▃▄▄▄▄▃▃▂▂▂▃▃▃▃▃▃▃▂▂▂▂▃▃▄▅▅▅▆▆▆▆▅▅▄▃ ▅▆▆▇▇▇▆▅▄▃▂▂▁▁ ▁▂▂▃▄▅▅▆▆▅▄▃▂▂▂▂▂▂▃▃▄▄▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▃▄▅▅▆▆▆▆▆▆▅▄▄▃ ▅▆▆▆▆▆▅▄▃▂▁▁▁ ▁▂▃▃▄▅▅▅▅▄▃▂▁▁▁▁▁▂▂▃▄▄▃▃▂▂▂▁▁▁▁▁▁▁▁▁▁▂▃▄▅▆▆▆▆▆▆▆▅▅▄▄▃ ▅▅▆▆▆▅▄▃▂▁▁▁ ▁▁▂▃▄▄▅▅▅▄▃▂▁▁ ▁▁▂▃▄▄▄▃▃▂▂▁▁▁▁▁▁ ▁▁▂▃▄▅▆▆▆▆▆▆▆▅▅▄▄▄ ▄▅▅▅▅▄▃▂▁▁▁▁▁ ▁▁▁▂▃▄▄▅▅▅▅▄▃▁▁ ▁▂▃▄▅▅▅▄▄▃▂▁▁ ▁▁▂▄▅▆▆▆▆▆▅▅▅▅▅▅▅▄ ▄▄▄▄▄▃▂▁▁▁▁▁▁▁▁▁▂▃▃▄▅▆▆▆▅▄▃▁▁ ▁▁▂▄▅▅▅▅▅▄▃▂▂▁ ▁▁▂▃▅▆▆▆▆▅▅▄▄▄▄▅▅▅▅ ▃▄▄▄▃▃▂▁▁▁▁▂▂▂▂▂▃▃▄▅▅▆▆▆▅▄▃▂▁▁▁▁▁▂▃▅▅▆▆▆▅▅▄▃▂▁▁▁▁▁▁▁▂▃▄▅▆▆▆▆▅▄▃▃▃▄▄▅▅▆ ▃▄▄▄▄▃▂▂▂▂▂▃▃▃▃▃▃▄▄▅▅▆▆▆▅▅▄▃▂▂▂▂▃▃▄▅▆▆▆▆▅▅▄▃▂▁▁▁▁▂▂▂▃▄▅▆▇▆▆▅▄▃▃▂▃▃▄▅▅▆ ▃▄▄▄▄▃▃▃▂▃▃▄▄▄▄▄▃▃▄▄▅▅▆▆▅▅▄▃▃▃▃▃▄▄▅▆▆▆▆▅▅▄▃▃▂▂▂▂▂▃▃▄▄▅▆▇▇▇▆▅▄▃▂▂▂▃▄▄▅▅ ▄▅▅▅▅▄▄▃▃▃▄▅▅▅▄▄▃▃▃▃▄▅▅▅▅▅▅▄▄▄▄▄▅▅▆▆▆▆▅▅▄▃▃▂▂▂▂▂▃▄▄▅▅▆▇▇▇▇▆▅▄▃▂▂▂▂▃▄▄▄ ▅▅▆▆▅▅▅▄▄▄▅▅▅▅▅▄▃▂▂▃▃▄▄▅▅▅▅▅▅▅▅▅▆▆▆▆▆▅▄▄▃▃▂▂▂▂▂▃▄▄▅▅▆▇▇▇▇▇▆▅▄▃▂▂▂▂▂▃▃▃ ▆▆▆▆▆▆▅▅▅▅▆▆▆▆▅▄▃▂▂▂▂▃▃▄▅▅▆▆▆▆▆▆▆▇▆▆▅▄▃▃▂▂▁▁▁▂▂▃▄▅▅▆▆▇▇██▇▇▆▅▄▃▂▂▂▂▂▃▃ ▆▇▇▇▇▆▆▆▆▆▆▇▇▆▅▄▃▂▁▁▁▂▂▃▄▅▆▆▇▇▇▇▇▇▇▆▅▄▃▂▁▁▁▁▁▁▂▃▄▅▅▆▆▇▇██▇▇▆▅▄▄▃▂▂▂▂▂▂ ▆▇▇▇▇▇▆▆▆▆▇▇▇▇▆▄▃▁▁▁▁▁▁▂▄▅▆▇▇████▇▇▆▅▃▂▁▁▁ ▁▁▂▃▄▅▅▅▆▆▇▇▇▇▇▇▆▅▄▃▃▂▂▂▂▂ ▆▇▇▇▇▇▆▆▆▆▇▇▇▇▆▅▃▁▁ ▁▁▂▃▅▆▇█████▇▇▆▅▃▂▁▁ ▁▁▂▃▄▄▄▄▅▅▆▇▇▇▇▇▆▆▅▄▃▂▂▂▂▃ ▆▇▇▇▇▆▆▅▅▆▆▇▇▇▇▅▄▂▁▁▁▁▁▂▃▅▆▇███▇▇▇▆▆▅▄▃▂▁▁ ▁▁▂▃▄▄▄▃▄▄▅▆▇▇▇▇▇▆▅▄▃▃▂▂▃▃ ▅▆▇▇▆▆▅▅▅▅▆▇▇▇▇▆▄▃▂▁▁▁▁▂▃▅▆▇▇▇▇▇▇▆▆▆▅▄▃▂▂▁▁▁▁▂▃▃▄▄▃▃▃▃▄▅▆▆▇▇▆▆▅▄▃▂▂▂▃▃ ▅▆▆▆▆▅▄▄▄▄▅▆▇▇▇▆▅▄▃▂▂▂▂▂▃▄▅▆▆▆▆▆▅▅▅▅▅▅▄▃▃▂▁▁▂▂▃▄▄▄▃▂▂▂▃▄▅▆▆▆▆▅▅▄▃▂▂▂▃▄ ▄▅▆▆▅▄▄▃▃▄▄▅▆▇▇▇▆▅▄▃▃▃▃▃▄▄▅▅▆▅▅▅▄▅▅▅▅▅▅▄▃▃▂▂▂▃▄▄▄▄▃▃▂▂▃▃▄▅▅▅▅▄▄▃▂▂▂▂▃▄ ▄▅▅▅▅▄▃▃▃▃▄▅▆▇▇▇▆▆▅▄▄▄▄▄▄▄▅▅▅▄▄▄▄▄▄▅▅▆▅▅▄▃▃▃▃▄▄▅▅▅▄▃▃▃▃▃▄▄▄▄▄▄▃▂▁▁▁▂▂▃ ▄▅▅▅▅▄▃▃▂▃▄▅▆▆▇▇▇▆▆▅▅▅▄▄▄▄▄▄▄▄▃▃▃▃▄▅▆▆▆▅▅▄▃▃▄▄▅▅▆▅▅▄▄▃▃▃▃▃▄▃▃▃▂▁▁▁▁▁▂▃ ▃▄▅▅▄▄▃▃▃▃▄▅▆▆▇▇▇▇▆▆▅▅▅▅▅▄▄▄▄▃▃▂▂▃▄▅▆▆▆▆▅▄▄▄▄▅▆▆▆▆▆▅▅▄▃▃▃▃▂▂▂▂▁▁▁ ▁▁▂▃ ▃▃▄▄▄▄▃▃▃▄▄▅▆▇▇▇▇▇▆▆▆▅▅▅▅▄▄▄▄▃▃▃▃▃▄▅▆▇▇▆▆▅▅▄▅▅▆▇▇▇▆▆▆▅▄▃▂▂▁▁▁▁▁ ▁▁▂▃ ▂▃▃▄▄▄▄▄▄▄▅▆▆▇▇▇▇▇▆▆▅▅▅▄▄▄▄▄▄▄▃▃▃▄▅▆▇▇▇▇▆▅▅▅▅▅▆▇▇▇▇▇▆▆▄▃▂▁▁▁▁ ▁▁▂▃▃ ▁▂▃▃▄▄▄▄▅▅▆▆▇▇▇▇▇▇▆▅▅▄▄▄▄▄▄▅▅▅▄▄▄▅▆▇▇▇▇▇▆▆▅▄▄▅▅▆▇▇▇▇▇▆▅▃▂▁▁ ▁▁▁▂▂▃▄ ▁▂▃▃▄▄▅▅▅▆▆▆▇▇▇▇▇▆▅▅▄▃▃▃▃▄▄▅▅▅▅▅▅▅▆▇▇▇▇▇▆▅▄▄▄▄▄▅▆▇▇▇▇▆▅▄▂▁▁ ▁▁▁▁▁▂▂▃▄▅ ▂▂▃▃▄▅▅▅▆▆▆▆▆▇▇▇▆▆▅▄▃▃▂▂▃▃▄▅▅▆▅▅▅▆▆▇▇▇▇▆▆▅▄▃▃▃▃▄▅▆▆▇▇▆▅▄▃▂▁▁▁▁▂▂▂▃▃▄▄▅ ▂▃▃▄▅▅▅▅▆▆▆▆▆▆▆▆▆▅▅▄▃▃▂▂▂▃▄▅▅▆▅▅▅▆▆▇▇▇▆▆▅▄▃▂▂▂▂▃▄▅▆▆▆▆▅▄▃▂▂▂▂▃▃▃▃▄▄▄▄▅ ▃▄▄▅▅▅▅▅▅▅▅▅▅▆▆▆▆▆▅▄▃▃▂▂▂▃▄▄▅▅▅▅▅▅▆▆▇▆▆▅▄▃▂▂▁▁▁▂▃▄▅▅▆▆▅▄▃▃▃▃▃▄▄▄▄▄▄▄▄▄ ▄▄▅▅▅▅▅▄▄▄▄▄▄▅▅▆▆▆▅▅▄▃▃▂▂▃▃▄▄▄▄▄▄▅▅▆▆▆▆▅▄▃▂▁▁▁▁▁▂▃▄▅▅▅▅▄▄▃▃▃▄▅▅▅▅▄▄▃▃▄ ▅▅▆▆▅▅▄▄▃▃▃▃▄▄▅▆▆▆▆▅▅▄▃▃▃▃▃▃▃▃▃▃▃▄▄▅▆▆▅▅▄▃▂▁ ▁▂▂▃▄▄▅▅▄▄▄▄▄▅▅▅▅▅▄▃▃▃▃ ▆▆▆▆▆▅▄▃▃▂▂▃▃▄▅▆▆▆▆▆▅▅▄▃▃▂▂▂▂▂▂▂▂▂▃▄▅▅▅▄▃▃▂▁ ▁▁▂▂▃▃▄▄▄▄▄▄▅▅▆▆▆▅▄▃▃▂▂ ▆▇▇▇▆▅▄▃▂▂▂▂▃▄▅▅▆▆▆▆▆▅▅▄▃▃▂▂▁▁▁▁▁▁▂▃▄▄▄▄▃▃▂▁▁ ▁▁▁▂▂▃▃▃▃▄▄▅▅▆▆▆▅▅▄▃▃▃ ▇▇▇▇▆▅▄▃▂▂▂▃▃▄▅▅▆▆▆▆▆▆▅▅▄▃▂▁▁▁ ▁▁▂▃▄▄▄▄▃▃▂▁▁▁ ▁▁▁▁▂▂▂▂▃▄▄▅▅▆▆▆▅▄▄▃▃ ▇▇▇▇▇▆▄▃▃▂▃▃▄▄▅▅▅▅▆▆▆▆▆▅▅▄▃▂▁ ▁▁▂▃▄▄▄▄▄▃▃▂▁▁▁▁▁▁▁▁▁▁▂▂▃▄▄▅▅▆▆▆▅▅▄▄ ▇▇▇▇▇▆▄▃▃▃▄▄▅▅▅▅▅▅▅▅▅▆▆▆▆▅▃▂▁▁ ▁▁▂▃▄▄▅▅▅▄▃▃▂▁▁▁▁▁ ▁▁▁▂▃▄▄▅▅▆▆▆▆▅▅ ▆▇▇▇▆▅▄▄▃▄▄▅▅▅▅▅▄▄▄▄▅▆▆▆▆▆▅▃▂▁▁▁ ▁▁▂▃▄▄▅▆▆▆▅▄▃▂▂▁▁▁▁ ▁▁▂▂▃▄▅▅▆▆▆▆▆▆ ▅▆▆▆▆▅▄▄▃▄▅▅▆▅▅▄▄▃▃▄▄▅▆▇▇▆▆▄▃▂▂▂▁▁▁▁▁▂▃▄▄▅▆▆▇▆▆▄▃▃▂▂▁▁▁ ▁▁▂▂▃▄▄▅▆▇▇▆▆▆ ▄▅▆▆▅▅▄▃▃▄▄▅▆▅▅▄▃▃▃▃▄▅▆▇▇▇▆▅▄▄▃▃▂▁▁▁▁▁▂▃▄▅▆▇▇▇▆▆▅▄▃▃▂▁▁▁▁▁▂▃▃▄▅▆▆▇▇▆▆▅ ▄▅▅▅▅▄▃▃▃▃▄▅▅▅▄▄▃▂▃▃▄▅▆▇▇▇▇▆▅▅▄▃▃▂▁▁▁▁▂▃▄▅▆▇▇▇▇▆▅▅▄▃▃▂▂▁▁▂▃▃▄▅▅▆▆▇▆▆▅▅ ▄▄▅▅▅▄▃▃▂▃▄▄▅▅▄▃▃▂▃▃▄▅▆▇▇▇▇▇▆▅▅▄▄▃▂▁▁▁▂▃▄▅▆▇▇▇▇▇▆▅▅▄▄▃▂▂▂▃▃▄▅▅▆▆▇▆▆▅▄▄ ▃▄▄▅▄▄▃▂▂▃▃▄▄▄▄▃▃▂▃▃▄▅▆▇███▇▇▆▆▆▅▄▃▂▁▂▂▃▄▄▅▆▇▇▇▇▆▆▅▅▄▃▃▃▃▃▄▅▆▆▇▇▇▆▅▄▃▂ ▂▃▄▄▄▄▃▃▃▃▃▄▄▄▃▃▃▃▃▄▅▆▇▇█████▇▇▇▆▅▄▃▃▂▃▃▄▄▅▆▇▇▇▆▆▅▅▅▄▃▃▃▃▄▅▅▆▇▇▇▇▆▅▃▂▁ ▂▃▃▄▄▄▄▃▃▃▃▄▄▃▃▃▃▃▄▄▅▆▇████████▇▇▆▆▅▄▄▄▄▄▅▅▅▆▆▆▆▅▅▄▄▄▃▃▃▃▄▅▆▆▇▇▇▇▆▄▂▁▁ ▂▂▃▄▅▅▅▄▄▄▄▄▃▃▃▃▃▃▄▅▆▆▇██████████▇▇▆▆▅▅▅▅▅▅▅▅▅▅▄▄▄▄▃▃▃▃▃▃▄▅▆▆▇▇▇▆▅▃▂▁ ▂▂▃▅▅▆▆▆▅▅▄▄▃▃▂▂▃▃▄▅▆▇▇▇██████████▇▇▇▆▆▅▅▅▄▄▄▃▃▃▃▃▃▃▃▂▂▂▃▃▄▅▆▇▇▇▆▅▃▂▁ ▂▃▄▅▆▇▇▆▆▅▅▄▃▂▂▂▂▃▄▅▆▆▇▇▇▇▇▇▇▇▇▇▇██▇▇▇▆▆▅▅▄▃▃▂▂▂▂▂▃▃▂▂▂▂▂▃▃▄▅▆▇▇▆▅▃▂▁▁ ▃▄▅▆▇▇▇▇▆▅▅▄▃▂▁▁▂▃▄▅▅▆▆▇▇▇▆▆▆▆▆▆▇▇▇▇▇▇▆▆▅▄▃▃▂▂▂▂▂▂▃▃▂▂▂▂▂▂▃▄▅▆▆▆▆▅▄▃▂▂ ▃▄▅▆▇▇▇▇▆▅▄▃▂▂▁▁▁▂▃▄▅▅▆▆▆▆▅▅▅▅▅▅▆▇▇▇▇▇▆▅▅▄▃▂▂▂▂▂▃▃▃▃▃▃▂▂▂▂▂▃▄▅▆▆▆▅▅▄▃▃ ▄▅▆▇▇█▇▇▆▅▄▃▂▁▁▁▁▁▂▃▄▅▅▅▅▅▄▄▄▄▄▄▅▆▆▇▇▆▆▅▄▃▂▂▂▂▂▃▃▄▄▄▄▃▃▂▂▂▂▃▄▅▆▆▆▆▅▅▄▄ ▅▅▆▇██▇▇▆▅▄▃▂▁ ▁▂▃▃▄▄▅▅▄▄▃▃▃▃▄▄▅▆▆▆▆▅▄▃▃▂▂▁▂▂▃▄▅▅▅▅▄▃▂▂▂▂▃▄▅▆▆▆▆▆▅▅▅ ▅▆▇▇██▇▆▅▄▃▂▁▁ ▁▁▂▃▄▄▄▄▄▃▃▂▂▃▃▄▄▅▅▅▅▄▃▃▂▁▁▁▂▃▄▅▅▅▅▅▄▃▂▂▂▂▂▃▄▅▆▆▆▆▆▆▆ ▆▇▇███▇▆▅▃▂▂▁ ▁▁▂▃▄▄▄▄▄▃▃▃▂▃▃▃▄▄▄▄▄▃▂▂▁▁▁▁▁▂▃▅▅▅▅▅▄▃▂▁▁▁▂▃▃▄▅▆▇▇▇▇▇ ▇▇████▇▆▄▃▂▁▁ ▁▂▃▃▄▅▅▅▅▄▄▃▃▃▃▃▄▄▄▃▃▂▂▁▁ ▁▁▂▃▄▅▅▅▄▄▃▂▁▁▁▁▂▃▄▅▆▇▇███ ▇▇████▇▆▄▃▂▁▁ ▁▂▃▄▅▅▆▆▆▅▅▄▄▄▄▄▄▃▃▃▂▂▁▁ ▁▂▂▃▄▄▄▄▃▂▁▁▁▁▁▁▂▃▄▆▇▇███ ▇▇████▇▆▄▃▂▁▁ ▁▂▃▄▅▅▆▆▇▇▆▆▅▅▄▄▄▄▃▃▃▂▂▁▁▁ ▁▁▂▃▃▃▃▃▂▂▁▁▁▁▁▁▂▃▄▆▇▇███ ▆▇▇███▇▆▅▃▂▂▁ ▁▂▃▄▅▆▆▇▇▇▇▇▆▅▅▄▄▄▃▃▃▃▂▂▁▁▁▁▁▁▁▂▂▃▃▃▂▂▁▁▁▁▁▁▂▂▃▄▆▆▇▇▇▇ ▅▆▇▇██▇▆▅▄▃▂▁▁ ▁▁▂▃▄▅▆▆▇▇█▇▇▆▆▅▅▄▄▄▃▃▃▃▃▂▂▁▁▁▁▂▂▂▃▃▃▂▂▂▁▁▁▁▂▂▃▄▅▆▆▇▇▇▆ ▅▅▆▇██▇▇▆▅▄▃▂▁▁▁▁▂▃▄▅▅▆▇▇▇▇▇▆▅▅▄▄▃▃▄▄▄▄▄▃▃▂▂▂▂▂▃▃▃▃▃▃▃▂▂▂▂▂▃▃▄▄▅▆▆▆▆▆▅ ▄▅▆▇▇█▇▇▆▅▄▃▂▁▁▁▁▁▂▃▄▅▆▆▇▇▇▆▅▅▄▃▃▃▃▄▄▄▅▄▄▄▃▃▃▃▃▄▄▄▄▄▄▃▃▃▃▃▃▄▄▄▅▆▆▆▆▆▅▄ ▃▄▅▆▇▇▇▇▆▅▄▃▂▁▁▁▁▁▂▃▃▄▅▆▆▆▆▆▅▄▃▃▂▃▃▄▅▅▅▅▅▄▄▄▄▄▄▅▅▅▅▅▅▄▄▄▄▄▄▄▅▅▆▆▆▆▆▅▄▄ ▃▄▅▆▇▇▇▇▇▆▅▄▃▂▁▁▁▁▂▂▃▄▄▅▆▆▅▅▄▃▃▂▂▂▃▄▅▆▆▆▆▆▅▅▅▅▅▆▆▆▆▆▆▆▅▅▅▅▅▅▆▆▇▇▇▆▆▅▄▃ ▃▄▄▆▇▇▇▇▇▆▅▄▃▂▁▁▁▁▂▃▃▄▄▅▅▅▄▄▃▃▂▂▂▃▄▅▆▇▇▇▇▇▆▆▆▆▇▇▇▇▇▇▇▇▆▆▅▅▆▆▆▇▇▇▇▇▆▅▄▃ ▃▃▄▅▆▇▇▇▇▆▅▄▃▂▂▁▂▂▃▃▃▄▄▄▄▄▄▃▃▃▂▂▃▄▅▆▇████▇▇▇▇▇▇██████▇▇▆▆▆▆▆▇▇███▇▇▆▅▄ ▃▄▄▅▆▆▇▇▆▆▅▄▃▂▂▂▃▃▄▄▄▄▄▄▃▃▃▃▃▃▃▃▄▅▆▇▇█████▇▇▇▇███████▇▇▆▆▆▆▆▇▇████▇▆▅▅ ▄▄▄▄▅▆▆▆▆▆▅▄▃▂▂▃▃▄▅▅▅▄▄▃▃▂▂▂▂▃▃▄▅▆▇▇█████▇▇▇▇▇▇█████▇▇▆▆▅▅▅▆▇▇████▇▇▆▅ ▄▄▄▄▄▅▆▆▆▅▄▃▃▃▃▃▄▅▅▅▅▅▄▃▂▂▂▂▂▃▄▅▆▆▇███▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▆▅▄▄▄▄▅▆▇▇███▇▇▆▆ ▄▄▃▄▄▅▅▆▆▅▄▃▃▂▃▄▄▅▆▆▅▄▃▂▂▁▁▂▂▃▄▅▆▇▇▇▇▇▇▆▆▆▆▆▆▆▆▆▆▆▆▆▆▅▄▃▃▃▃▄▅▆▇▇▇▇▇▇▆▆ ▄▄▃▃▄▄▅▅▅▅▄▃▂▂▃▃▄▅▅▅▅▄▃▂▁▁▁▁▂▃▄▅▆▇▇▇▇▇▆▅▅▅▅▄▄▅▅▅▅▅▅▅▄▄▃▂▂▂▃▃▄▅▆▇▇▇▇▆▆▅ ▄▃▃▃▃▄▅▅▅▅▄▃▂▂▃▃▄▅▅▅▄▃▂▁▁▁▁▁▂▃▄▅▆▇▇▇▆▆▅▄▄▄▃▃▃▃▄▄▄▄▄▄▃▃▂▂▁▂▂▃▄▅▆▆▇▇▆▆▅▄ ▄▃▂▃▃▄▅▅▆▅▄▃▃▂▂▃▃▄▄▄▃▂▂▁ ▁▂▃▄▅▆▆▆▆▆▅▄▃▃▃▃▂▂▂▃▃▃▃▃▃▂▂▁▁▁▁▂▃▄▅▅▆▆▆▅▅▄▃ ▃▃▂▃▃▄▅▆▆▅▅▄▃▃▃▃▃▃▃▃▂▂▁ ▁▂▃▃▄▅▆▆▆▅▄▄▃▃▂▂▂▂▂▂▂▂▂▂▂▂▁▁▁▁▁▁▂▃▄▅▅▆▅▄▄▃▂ ▄▃▂▃▃▄▅▆▆▆▅▄▄▃▃▃▃▃▂▂▁▁ ▁▂▃▃▄▅▅▅▅▅▄▃▃▃▂▂▂▁▁▁▁▁▁▁▁▁▁ ▁▁▂▂▃▄▅▅▄▃▂▂▁ ▄▃▃▃▄▅▆▆▇▇▆▅▅▄▄▃▃▂▂▁▁▁ ▁▁▂▃▃▄▄▅▅▅▅▄▄▃▃▃▂▁▁▁ ▁▁▁▁▁ ▁▁▂▃▃▄▄▄▃▂▁▁ ▄▄▃▃▄▅▆▇▇▇▆▆▅▅▄▄▃▂▂▁▁ ▁▁▂▃▃▄▄▄▄▄▅▅▅▄▄▄▃▃▂▁▁ ▁▁▁▁▁ ▁▁▂▂▃▄▄▃▃▂▁ ▅▄▄▄▄▅▆▆▇▇▇▆▆▅▅▄▃▃▂▁▁▁ ▁▂▂▃▄▄▄▃▃▃▄▄▅▅▅▅▄▄▃▂▁▁ ▁▁▁▁▁▁▁▁▁▁▁▂▂▃▄▄▄▃▂▁▁ ▅▄▄▄▄▄▅▆▇▇▆▆▆▆▅▅▄▃▃▂▁▁▁▁▂▃▄▄▅▅▄▃▃▃▃▄▅▅▆▅▅▄▄▂▁▁ ▁▁▂▂▂▂▂▂▁▁▁▁▂▃▄▄▅▄▄▃▂▁ ▅▄▄▃▃▄▅▅▆▆▆▆▆▅▅▅▅▄▄▃▂▂▂▂▃▄▅▅▅▅▄▃▃▃▃▄▅▅▆▆▅▅▄▂▂▁▁▁▁▂▂▃▃▃▃▂▂▂▂▂▃▃▄▅▅▅▅▄▃▂ ▅▄▃▃▃▃▄▄▅▅▅▅▅▅▅▅▅▅▄▄▃▃▂▃▄▄▅▆▆▅▄▃▃▂▃▃▄▅▅▅▅▄▃▂▁▁▁▁▂▃▃▄▄▄▄▃▃▂▂▃▃▄▅▆▆▆▆▅▄▄ ▄▃▃▂▂▂▃▄▄▄▄▄▄▄▅▅▅▅▅▅▄▃▃▄▄▅▅▆▆▅▄▃▂▂▂▃▄▄▅▄▄▃▃▂▁▁▁▂▂▃▄▅▅▅▅▄▃▃▃▃▄▅▆▆▇▇▇▆▅▅ ▃▃▂▂▂▂▂▃▃▃▃▃▃▄▄▅▆▆▆▅▅▄▄▄▅▅▆▆▆▅▄▃▂▂▂▂▃▄▄▄▃▃▂▁▁▁▁▂▃▄▅▅▆▆▅▅▄▄▄▄▅▅▆▇▇▇▇▇▆▅ ▃▂▂▁▁▁▁▂▂▂▂▂▂▃▄▅▆▆▇▆▆▅▅▅▅▆▆▆▅▅▄▃▂▂▂▂▃▃▃▃▃▂▂▁▁▁▂▂▃▄▅▆▆▆▆▅▅▄▄▅▅▆▇▇███▇▇▆ ▃▂▂▁▁▁▁▁▁▁▁▁▁▂▃▅▆▇▇▇▇▆▆▆▆▆▆▆▅▅▄▃▂▂▂▂▃▃▃▃▃▂▂▁▁▂▂▃▄▅▆▆▆▆▆▅▅▅▅▆▆▇▇██████▇ ▃▂▂▁▁▁▁▁▁ ▁▂▄▆▇██▇▇▇▇▇▇▇▆▅▄▃▃▂▂▂▂▃▄▄▄▃▃▂▂▂▃▃▄▅▆▆▆▆▆▅▅▅▅▅▆▇▇████████ ▄▃▂▁▁▁▁ ▁▂▄▆▇████▇▇▇▇▇▆▅▄▃▂▂▂▂▃▃▄▅▄▄▃▃▃▃▄▄▅▆▆▆▆▅▅▅▄▄▅▅▆▇▇████████ ▄▃▂▂▁▁▁▁▁▁ ▁▂▃▅▇▇██▇▇██▇▇▆▆▄▃▃▂▂▂▃▄▅▅▅▅▄▄▄▄▅▅▆▆▆▆▅▅▄▃▃▄▄▅▆▇▇████████ ▄▄▃▂▂▁▁▁▁▁▁▁▁▁▂▃▅▆▇▇▇▇▇▇▇▇▇▆▆▅▄▃▂▂▂▃▄▅▆▆▅▅▄▄▅▅▆▆▆▆▅▄▄▃▂▂▂▃▄▅▆▇▇███▇▇▇▇ ▅▄▃▂▂▂▂▂▂▂▂▂▁▂▂▃▄▅▆▆▆▆▆▇▇▇▇▆▆▅▄▃▂▂▃▃▄▅▆▆▅▅▄▅▅▆▆▆▆▅▅▄▃▂▁▁▂▂▄▅▅▆▇▇▇▇▆▆▆▆ ▄▄▃▂▂▃▃▃▄▃▃▃▂▂▂▃▃▄▅▅▅▅▆▆▇▇▇▆▆▅▄▃▂▂▃▃▄▅▅▅▅▄▄▄▅▅▆▆▆▅▄▃▂▁▁▁▁▂▃▄▅▅▆▆▆▆▅▅▅▅ ▄▃▃▂▂▃▃▄▄▄▄▄▃▃▃▃▃▃▄▄▄▄▅▅▆▇▇▆▆▅▄▃▂▂▂▃▄▄▅▅▄▃▃▄▄▅▆▆▆▅▄▃▂▁ ▁▁▂▃▄▅▅▆▅▅▅▄▄▄

Noise synthesis

Noise looks much more interesting when combined.

```ruby noises = Perlin::Noise.new(2) contrast = Perlin::Curve.contrast(Perlin::Curve::QUINTIC, 3)

(0..100).each do |x| n = 0 [[0.02, 10], [0.04, 10], [0.1, 20], [0.2, 15]].each_with_index do |step_scale, idx| step, scale = step_scale n += contrast.call( noises[idx, x * step] ) * scale end puts ‘=’ * n.floor end ```

```

========================================= =============================================== =============================================== ======================================== =========================== =================== ===================== ======================== =========================== ============================ ============================= ============================== ============================== ============================== =========================== ======================= ====================== ====================== ======================== ========================== ============================ =============================== ================================= ================================== ================================= ================================ ================================= ================================== ===================================== ====================================== ========================================= ================================================ ========================================================= =========================================================== ===================================================== ============================================== =============================================== ===================================================== ================================================= ================================= ================== ============= ============= ==================== ============================ ===================================== ============================================== ================================================ ============================================= ================================ ================== ============ =========== =========== ================== ========================= ========================== =========================== ================================ ================================ ================================== ========================================= ================================================== ==================================================== =============================================== ========================================= ========================================== ============================================== ============================================ =============================== ================ ========== ======== ========== ============= =================== ========================== =============================== ================================ ========================= ================ =========== ======= ====== ============= ==================== ====================== ======================== ============================= =============================== ================================== ======================================= ======================================== ========================================= ================================================ ====================================================== ====================================================== =============================================== ====================================== ================================ ```

References

  • Texturing & modeling: a procedural approach by David S. Ebert et al.
  • Improving Noise by Ken Perlin (http://mrl.nyu.edu/~perlin/paper445.pdf)
  • http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html#algorithm
  • http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
  • http://burtleburtle.net/bob/rand/unitvec.html
  • http://briansharpe.wordpress.com/2011/11/14/two-useful-interpolation-functions-for-noise-development/
  • http://http.developer.nvidia.com/GPUGems/gpugems_ch05.html
  • http://www.java-gaming.org/index.php?topic=22796.0