I’d like to have an M x N array of characters which I can address (say,
by
Row and column) and update or read any spot (M,N). This array would map
directly to a window. can anyone suggest the best/easiest way to
implement
this? In other words, I’m looking for a way to display an array of
characters to a Window…
Thanks,
Chuck
Ps. I have FXRuby installed, I probably just need to be shown a sarting
point maybe an FX Ruby function???
I have no idea how FXRuby works, but I guess every GUI framework has
some kind of table object. For example, in Ruby-GNOME2 you’d use a
Gtk::Table and put a Gtk::Label with the corresponding character in
every cell.
However, you won’t be able to base this table on a normal array so that
every change to the array also affects the GUI object. You’ll need a
custom array/matrix object for that, which updates the GUI object on
every change.
require ‘ruiby’
M=12
N=10
Ruiby.app width: 400, height:400 do
@matrix=[]
table(M,N) do
M.times {
line=[]
row {
N.times {
line << label(" ")
cell(line.last)
}
} @matrix << line
}
end
anim(10) do @matrix[rand(M)][rand(N)].text = (Time.now.to_i%10).to_s
end
end