class MatrixTrails::Generator

Public Class Methods

new(row, column) click to toggle source
# File lib/matrixtrails/generator.rb, line 4
def initialize row, column
  array = []
  row.times do
    col = []
    column.times do 
      col.push(rand 100)
    end
    array.push col
  end
  @core = Core.new(array)
  @history_pos = []
end

Public Instance Methods

display() click to toggle source
# File lib/matrixtrails/generator.rb, line 17
def display
  @core.spiral_indexes.each do |pos|
    show_element(@core.array, pos)
    sleep(1)
  end
end

Private Instance Methods

is_current?(pos, x, y) click to toggle source
# File lib/matrixtrails/generator.rb, line 30
def is_current? pos, x, y
  pos[0] == x and pos[1] == y
end
is_printed?(x, y) click to toggle source
# File lib/matrixtrails/generator.rb, line 26
def is_printed? x, y
  @history_pos.include? [x, y]
end
need_separated_display?(pos, x, y) click to toggle source
# File lib/matrixtrails/generator.rb, line 34
def need_separated_display? pos, x, y
  is_current? pos, x, y or is_printed? x, y
end
show_element(array, pos) click to toggle source
# File lib/matrixtrails/generator.rb, line 38
def show_element(array, pos)
  array.each_with_index do |row, x| 
    row.each_with_index do |e, y|
      if need_separated_display? pos, x, y
        print e.to_s.green, " "
        @history_pos.push pos
      else
        print e, " "
      end
    end
    puts ""
  end
  puts ""
end