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.
6
7
8
9
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 6
def initialize(data, mod)
@raw = data.dup
@module = mod
end
|
Instance Method Details
#clear(val = "0") ⇒ Object
11
12
13
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 11
def clear(val = "0")
@raw = val * @module * h
end
|
#draw_numbered_polygons(polygons) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 62
def draw_numbered_polygons(polygons)
polygons.each do |polygon|
color = "A"
polygon[:outer].each_with_index do |position, index|
value_set(position[:x], position[:y], color)
color = next_color(color)
end
polygon[:inner].each do |sequence|
color = "a"
sequence.each_with_index do |position, index|
value_set(position[:x], position[:y], color)
color = next_color(color)
end
end
end
end
|
#draw_polygons(polygons) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 48
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
|
#draw_rect(x:, y:, width:, height:, color: "o", filled: true) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 38
def draw_rect(x:, y:, width:, height:, color: "o", filled: true)
(y...(y + height)).each do |row|
(x...(x + width)).each do |col|
if filled || row == y || row == y + height - 1 || col == x || col == x + width - 1
value_set(col, row, color)
end
end
end
end
|
#dup! ⇒ Object
34
35
36
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 34
def dup!
ChunkyBitmap.new(@raw, @module)
end
|
#h ⇒ Object
19
20
21
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 19
def h
@raw.size / @module
end
|
#to_terminal(label = nil) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 79
def to_terminal(label = nil)
puts label if label
puts " " + (0...@module).map { |i| (i % 10).to_s }.join
n = 0
@raw.scan(/.{1,#{@module}}/).each do |line|
colored_line = line.chars.map { |c| colorize_char(c) }.join
puts "#{n} #{colored_line}"
n += 1
n = 0 if n >= 10
end
puts
end
|
#value_at(x, y) ⇒ Object
23
24
25
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 23
def value_at(x, y)
@raw[y * @module + x]
end
|
#value_set(x, y, value) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 27
def value_set(x, y, value)
return if y >= h
return if x >= w
@raw[y * @module + x] = value
end
|
#w ⇒ Object
15
16
17
|
# File 'lib/contrek/bitmaps/chunky_bitmap.rb', line 15
def w
@module
end
|