Class: TilePerlinGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/tile_perlin_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(perlin_config) ⇒ TilePerlinGenerator

Returns a new instance of TilePerlinGenerator.



8
9
10
# File 'lib/tile_perlin_generator.rb', line 8

def initialize(perlin_config)
  @perlin_config = perlin_config
end

Instance Attribute Details

#perlin_configObject (readonly)

Returns the value of attribute perlin_config.



6
7
8
# File 'lib/tile_perlin_generator.rb', line 6

def perlin_config
  @perlin_config
end

Instance Method Details

#generateObject



12
13
14
15
16
17
18
19
20
# File 'lib/tile_perlin_generator.rb', line 12

def generate
  Array.new(perlin_config.height) do |y|
    Array.new(perlin_config.width) do |x|
      nx = perlin_config.x_frequency * (x.to_f / perlin_config.width - 0.5)
      ny = perlin_config.y_frequency * (y.to_f / perlin_config.height - 0.5)
      with_adjustment((Math.cos(noise(nx, ny))**6))
    end
  end
end