Class: FromTo

Inherits:
Object
  • Object
show all
Defined in:
lib/A_Star.rb

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ FromTo

Returns a new instance of FromTo.



4
5
6
# File 'lib/A_Star.rb', line 4

def initialize image
  @image = image
end

Instance Method Details

#findEndObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/A_Star.rb', line 8

def findEnd
  0.upto @image.dimension.width - 1 do |i|
    red = ChunkyPNG::Color.r(@image[i, @image.dimension.height - 1])
    green = ChunkyPNG::Color.g(@image[i, @image.dimension.height - 1])
    blue = ChunkyPNG::Color.b(@image[i, @image.dimension.height - 1])

    if red > 255/2 && green > 255/2 && blue > 255/2
      return [i, @image.dimension.height - 1]
    end
  end
  return Array.new
end

#findStartObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/A_Star.rb', line 21

def findStart
  0.upto @image.dimension.width - 1 do |i|
    red = ChunkyPNG::Color.r(@image[i, 0])
    green = ChunkyPNG::Color.g(@image[i, 0])
    blue = ChunkyPNG::Color.b(@image[i, 0])

    if red > 255/2 && green > 255/2 && blue > 255/2
      return [i, 0]
    end
  end
  return Array.new
end