Class: Axon::Noise
- Inherits:
-
Object
- Object
- Axon::Noise
- Defined in:
- lib/axon/generators.rb
Overview
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
The components in the generated image.
-
#height ⇒ Object
readonly
The height of the generated image.
-
#lineno ⇒ Object
readonly
The index of the next line that will be fetched by gets, starting at 0.
-
#width ⇒ Object
readonly
The width of the generated image.
Instance Method Summary collapse
-
#gets ⇒ Object
Gets the next scanline from the generated image.
-
#initialize(width, height, options = nil) ⇒ Noise
constructor
:call-seq: Noise.new(width, height, options = {}).
Constructor Details
#initialize(width, height, options = nil) ⇒ Noise
:call-seq:
Noise.new(width, height, = {})
Creates a new noise image object with dimensions width x height.
options may contain the following optional hash key values:
-
:components – The number of components in the generated image.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/axon/generators.rb', line 32 def initialize(width, height, =nil) ||= {} @width = width @height = height @components = [:components] || 3 @lineno = 0 @empty_string = String.new if @empty_string.respond_to? :force_encoding @empty_string.force_encoding('BINARY') end end |
Instance Attribute Details
#components ⇒ Object (readonly)
The components in the generated image.
18 19 20 |
# File 'lib/axon/generators.rb', line 18 def components @components end |
#height ⇒ Object (readonly)
The height of the generated image.
15 16 17 |
# File 'lib/axon/generators.rb', line 15 def height @height end |
#lineno ⇒ Object (readonly)
The index of the next line that will be fetched by gets, starting at 0.
21 22 23 |
# File 'lib/axon/generators.rb', line 21 def lineno @lineno end |
#width ⇒ Object (readonly)
The width of the generated image.
12 13 14 |
# File 'lib/axon/generators.rb', line 12 def width @width end |
Instance Method Details
#gets ⇒ Object
Gets the next scanline from the generated image.
47 48 49 50 51 52 53 |
# File 'lib/axon/generators.rb', line 47 def gets return nil if @lineno >= @height sl = @empty_string.dup (@width * @components).times{ sl << rand(2**8) } @lineno += 1 sl end |