Class: Axon::Noise
- Inherits:
-
Object
- Object
- Axon::Noise
- Defined in:
- lib/axon/generators.rb
Overview
Instance Attribute Summary collapse
-
#color_model ⇒ Object
readonly
The color model of the generated image.
-
#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:
-
:color_model – The color model of the generated image.
-
:components – The number of components in the generated image.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/axon/generators.rb', line 36 def initialize(width, height, =nil) ||= {} @width = width @height = height @color_model = [:color_model] || :RGB @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
#color_model ⇒ Object (readonly)
The color model of the generated image.
18 19 20 |
# File 'lib/axon/generators.rb', line 18 def color_model @color_model end |
#components ⇒ Object (readonly)
The components in the generated image.
21 22 23 |
# File 'lib/axon/generators.rb', line 21 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.
24 25 26 |
# File 'lib/axon/generators.rb', line 24 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.
52 53 54 55 56 57 58 |
# File 'lib/axon/generators.rb', line 52 def gets return nil if @lineno >= @height sl = @empty_string.dup (@width * @components).times{ sl << rand(2**8) } @lineno += 1 sl end |