Class: Axon::Solid

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

Overview

A Solid Color Image Generator

Axon::Solid will generate images with a solid color value.

Example

Axon::Solid.new(100, 200, "\x0A\x14\x69")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height, color = nil, color_model = nil) ⇒ Solid

:call-seq:

Solid.new(width, height, color = "\x00\x00\x00", color_model = :RGB)

Creates a new solid color image object with dimensions width x height.

The optional argument color is the binary value that will be assigned to each pixel.



93
94
95
96
97
98
99
# File 'lib/axon/generators.rb', line 93

def initialize(width, height, color=nil, color_model=nil)
  @width, @height = width, height
  @color = color || "\x00\x00\x00"
  @color_model = color_model || :RGB
  @components = @color.size
  @lineno = 0
end

Instance Attribute Details

#color_modelObject (readonly)

The color model of the generated image.



77
78
79
# File 'lib/axon/generators.rb', line 77

def color_model
  @color_model
end

#componentsObject (readonly)

The components in the generated image.



80
81
82
# File 'lib/axon/generators.rb', line 80

def components
  @components
end

#heightObject (readonly)

The height of the generated image.



74
75
76
# File 'lib/axon/generators.rb', line 74

def height
  @height
end

#linenoObject (readonly)

The index of the next line that will be fetched by gets, starting at 0.



83
84
85
# File 'lib/axon/generators.rb', line 83

def lineno
  @lineno
end

#widthObject (readonly)

The width of the generated image.



71
72
73
# File 'lib/axon/generators.rb', line 71

def width
  @width
end

Instance Method Details

#getsObject

Gets the next scanline from the generated image.



103
104
105
106
107
# File 'lib/axon/generators.rb', line 103

def gets
  return nil if @lineno >= @height
  @lineno += 1
  @color * width
end