If your array is a single size, you can map the x and y coordinates to the index of the array in the same way as the pixels in the vga buffer.
offset = y * buffer_width + x
100 , 5,5, 5 * 100 + 5 = 505 1- .
, . , 10x10 : 10 , buffer_width, , 10 , 10 10x10.
5 3x3:
buffer = ['0,0', '1,0', '2,0', '3,0', '4,0',
'0,1', '1,1', '2,1', '3,1', '4,1',
'0,2', '1,2', '2,2', '3,2', '4,2',
'0,3', '1,3', '2,3', '3,3', '4,3',
'0,4', '1,4', '2,4', '3,4', '4,4']
buffer_width = 5
buffer_height = 5
x1,y1 = 1,1
x2,y2 = 3,3
view_width = x2 - x1
view_height = y2 - y1
(0..view_height).each do |row|
offset = (y1 + row) * buffer_width + x1
puts buffer[offset..offset+view_width].inspect
end
:
["1,1", "2,1", "3,1"]
["1,2", "2,2", "3,2"]
["1,3", "2,3", "3,3"]
, .
, .