Class: Contrek::Bitmaps::Bitmap

Inherits:
Object
  • Object
show all
Includes:
Painting
Defined in:
lib/contrek/bitmaps/bitmap.rb

Direct Known Subclasses

ChunkyBitmap, PngBitmap

Instance Method Summary collapse

Methods included from Painting

#bitmap_colors, direct_draw_polygons, #draw_line

Instance Method Details

#clear!(color: " ") ⇒ Object



33
34
35
36
37
38
39
# File 'lib/contrek/bitmaps/bitmap.rb', line 33

def clear!(color: " ")
  w.times do |x|
    h.times do |y|
      value_set(x, y, color)
    end
  end
end

#copy_rect(src_bitmap:, src_x:, src_y:, dest_x:, dest_y:, rect_w:, rect_h:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/contrek/bitmaps/bitmap.rb', line 20

def copy_rect(src_bitmap:, src_x:, src_y:, dest_x:, dest_y:, rect_w:, rect_h:)
  rect_h.times do |hp|
    rect_w.times do |wp|
      src_pos_x = src_x + wp
      src_pos_y = src_y + hp
      src_color = src_bitmap.value_at(src_pos_x, src_pos_y)
      dest_pos_x = dest_x + wp
      dest_pos_y = dest_y + hp
      value_set(dest_pos_x, dest_pos_y, src_color)
    end
  end
end

#scan(start_x: 0, end_x: w) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/contrek/bitmaps/bitmap.rb', line 6

def scan(start_x: 0, end_x: w)
  x = start_x
  y = 0
  loop do
    yield x, y, value_at(x, y)
    x += 1
    if x == end_x
      x = start_x
      y += 1
      break if y == h
    end
  end
end