Class: Flico::Grid

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

Constant Summary collapse

GRID =
[[0,1,1,2], [3,4,5,6], [7,8,8,9]]
CANV_WIDTH =
1750
CANV_HEIGHT =
1250

Instance Method Summary collapse

Instance Method Details

#canv_heightObject



15
16
17
# File 'lib/flico/grid.rb', line 15

def canv_height
  CANV_HEIGHT
end

#canv_widthObject



11
12
13
# File 'lib/flico/grid.rb', line 11

def canv_width
  CANV_WIDTH
end

#cell_height(name) ⇒ Object



39
40
41
# File 'lib/flico/grid.rb', line 39

def cell_height(name)
  cell_size(CANV_HEIGHT, rows, size_multiplier(column_cells, name))
end

#cell_rectangle(name) ⇒ Object



65
66
67
68
# File 'lib/flico/grid.rb', line 65

def cell_rectangle(name)
  row, column = row_cells.find_index {|row| row.include? name }, column_cells.find_index {|row| row.include? name }
  Cell.new(column * (CANV_WIDTH / columns), row * (CANV_HEIGHT / rows), cell_width(name), cell_height(name))
end

#cell_width(name) ⇒ Object



35
36
37
# File 'lib/flico/grid.rb', line 35

def cell_width(name)
  cell_size(CANV_WIDTH, columns, size_multiplier(row_cells, name))
end

#column_cellsObject



23
24
25
# File 'lib/flico/grid.rb', line 23

def column_cells
  GRID.transpose
end

#columnsObject



19
20
21
# File 'lib/flico/grid.rb', line 19

def columns
  GRID.max_by(&:size).size
end

#crop_rectangle(cell_name, image_width, image_height) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/flico/grid.rb', line 43

def crop_rectangle(cell_name, image_width, image_height)
  x, y = 0, 0
  image = Cell.new(image_width, image_height)
  cell = cell_rectangle(cell_name)

  unless image.aspect_ratio >= cell.aspect_ratio
    final_width = image.width
    final_height = image.height - (image.height - (image.width / cell.aspect_ratio))
  else
    final_width = image_width - (image.width - (image.height * cell.aspect_ratio))
    final_height = image.height
  end

  crop_rectangle = Cell.new(x, y, final_width, final_height)
  crop_rectangle
end

#resize_rectangle(cell_name, image_width, image_height) ⇒ Object



60
61
62
63
# File 'lib/flico/grid.rb', line 60

def resize_rectangle(cell_name, image_width, image_height)
  image = Cell.new(image_width, image_height)
  cell_rectangle(cell_name)
end

#row_cellsObject



31
32
33
# File 'lib/flico/grid.rb', line 31

def row_cells
  GRID
end

#rowsObject



27
28
29
# File 'lib/flico/grid.rb', line 27

def rows
  GRID.size
end