Class: Pixelflut::TextImage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height) ⇒ TextImage

Returns a new instance of TextImage.



7
8
9
10
11
# File 'lib/pixelflut/text_image.rb', line 7

def initialize(width, height)
  @columns, @rows = width, height
  @row_inc = width * 4
  clear
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



5
6
7
# File 'lib/pixelflut/text_image.rb', line 5

def changes
  @changes
end

#columnsObject (readonly) Also known as: width

Returns the value of attribute columns.



5
6
7
# File 'lib/pixelflut/text_image.rb', line 5

def columns
  @columns
end

#rowsObject (readonly) Also known as: height

Returns the value of attribute rows.



5
6
7
# File 'lib/pixelflut/text_image.rb', line 5

def rows
  @rows
end

#to_blobObject (readonly)

Returns the value of attribute to_blob.



5
6
7
# File 'lib/pixelflut/text_image.rb', line 5

def to_blob
  @to_blob
end

Instance Method Details

#[]=(x, y, rrggbbaa) ⇒ Object

def [](x, y)

@@to_blob[(4 * (x + @columns * y)) % @data.size, 4].bytes.map! do |b|
  b = b.to_s(16)
  b = '0' + b if b.size == 1
  b
end.join

end



34
35
36
37
# File 'lib/pixelflut/text_image.rb', line 34

def []=(x, y, rrggbbaa)
  @to_blob[(4 * (x + @columns * y)) % @to_blob.size, 4] = as_color(rrggbbaa)
  @changes += 1
end

#changedObject



21
22
23
24
# File 'lib/pixelflut/text_image.rb', line 21

def changed
  @changes = 0
  self
end

#clearObject



16
17
18
19
# File 'lib/pixelflut/text_image.rb', line 16

def clear
  @to_blob = Black * (@columns * @rows)
  @changes = 1
end

#draw_rect(x1, y1, x2, y2, rrggbbaa) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pixelflut/text_image.rb', line 39

def draw_rect(x1, y1, x2, y2, rrggbbaa)
  x1, x2 = x2, x1 if x1 > x2
  y1, y2 = y2, y1 if y1 > y2
  color = as_color(rrggbbaa)
  pos = (4 * (x1 + @columns * y1)) % @to_blob.size
  pattern = color * (x2 - x1 + 1)
  (y2 - y1 + 1).times do
    @to_blob[pos, pattern.size] = pattern
    pos += @row_inc
  end
  @changes += 1
end