Class: Contrek::Bitmaps::ChunkyBitmap
- Inherits:
-
Bitmap
- Object
- Bitmap
- Contrek::Bitmaps::ChunkyBitmap
show all
- Defined in:
- lib/contrek/bitmaps/chunky_bitmap.rb
Instance Method Summary
collapse
Methods inherited from Bitmap
#clear!, #copy_rect, #scan
Methods included from Painting
#bitmap_colors, direct_draw_polygons, #draw_line
Constructor Details
#initialize(data, mod) ⇒ ChunkyBitmap
Returns a new instance of ChunkyBitmap.
4
5
6
7
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 4
def initialize(data, mod)
@raw = data.dup
@module = mod
end
|
Instance Method Details
#clear(val = "0") ⇒ Object
9
10
11
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 9
def clear(val = "0")
@raw = val * @module * h
end
|
#draw_polygons(polygons) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 36
def draw_polygons(polygons)
polygons.each do |polygon|
[[:outer, "o"], [:inner, "i"]].each do |side, color|
sequences = polygon[side]
sequences = [sequences] if side == :outer
sequences.each do |sequence|
sequence.each do |position|
value_set(position[:x], position[:y], color)
end
end
end
end
end
|
#dup! ⇒ Object
32
33
34
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 32
def dup!
ChunkyBitmap.new(@raw, @module)
end
|
#h ⇒ Object
17
18
19
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 17
def h
@raw.size / @module
end
|
#to_terminal ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 50
def to_terminal
puts " " + (0...@module).map { |i| (i % 10).to_s }.join
n = 0
@raw.scan(/.{1,#{@module}}/).each do |line|
puts n.to_s + " " + line
n += 1
n = 0 if n >= 10
end
puts
end
|
#value_at(x, y) ⇒ Object
21
22
23
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 21
def value_at(x, y)
@raw[y * @module + x]
end
|
#value_set(x, y, value) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 25
def value_set(x, y, value)
return if y >= h
return if x >= w
@raw[y * @module + x] = value
end
|
#w ⇒ Object
13
14
15
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 13
def w
@module
end
|