class Block
Constants
- PATTERN
Attributes
pattern[RW]
rotation[RW]
upper_left[RW]
Public Class Methods
new(pattern, upper_left)
click to toggle source
# File lib/block.rb, line 20 def initialize(pattern, upper_left) @pattern, @upper_left, @rotation = pattern, upper_left, 0 end
random(upper_left)
click to toggle source
# File lib/block.rb, line 24 def self.random(upper_left) Block.new(PATTERN.sample, upper_left) end
Public Instance Methods
get_vectors(rotation)
click to toggle source
# File lib/block.rb, line 36 def get_vectors(rotation) vectors = @pattern.pattern (rotation.abs % 4 ).times do vectors.map! do |coord| rotation > 0 ? rotate_coord_right(coord) : rotate_coord_left(coord) end end vectors end
rotate_coord_left(coord)
click to toggle source
# File lib/block.rb, line 54 def rotate_coord_left(coord) i, j = coord size = @pattern.size [(size - 1) - j, i] end
rotate_coord_right(coord)
click to toggle source
# File lib/block.rb, line 48 def rotate_coord_right(coord) i, j = coord size = @pattern.size [j , (size - 1) - i] end
spaces_occupied(options = {})
click to toggle source
# File lib/block.rb, line 28 def spaces_occupied(options = {}) rotation = options[:rotation] || @rotation pos = options[:pos] || @upper_left get_vectors(rotation).map do |vector| [vector.first + pos.first, vector.last + pos.last] end end