samples/05_mouse/03_mouse_move_paint_app/app/main.rb
def draw_grid x, y, h, w, lines_h, lines_v

    # The grid starts off empty.
    grid = []

    # Calculates the placement and adds horizontal lines or separators into the grid.
    curr_y = y # start at the bottom of the box
    dist_y = h / (lines_h + 1) # finds distance to place horizontal lines evenly throughout 500 height of grid
    lines_h.times do
      curr_y += dist_y # increment curr_y by the distance between the horizontal lines
      grid << horizontal_separator(curr_y, x, x + w - 1) # add a separator into the grid
    end

    # Calculates the placement and adds vertical lines or separators into the grid.
    curr_x = x # now start at the left of the box
    dist_x = w / (lines_v + 1) # finds distance to place vertical lines evenly throughout 500 width of grid
    lines_v.times do
      curr_x += dist_x # increment curr_x by the distance between the vertical lines
      grid << vertical_separator(curr_x, y + 1, y  + h) # add separator
    end

    # paint_grid uses a hash to assign values to keys.
    state.paint_grid ||= {"x" => x, "y" => y, "h" => h, "w" => w, "lines_h" => lines_h,
                          "lines_v" => lines_v, "dist_x" => dist_x,
                          "dist_y" => dist_y }

    return grid
  end
# Draws the grid by adding in vertical and horizontal separators.
Draws the grid by adding in vertical and horizontal separators.
Draws the grid by adding in vertical and horizontal separators .
def draw_grid x, y, h, w, lines_h, lines_v
    grid = []
    curr_y = y 
    dist_y = h / (lines_h + 1) 
    lines_h.times do
      curr_y += dist_y 
      grid << horizontal_separator(curr_y, x, x + w - 1) 
    end
    curr_x = x 
    dist_x = w / (lines_v + 1) 
    lines_v.times do
      curr_x += dist_x 
      grid << vertical_separator(curr_x, y + 1, y  + h) 
    end
    state.paint_grid ||= {"x" => x, "y" => y, "h" => h, "w" => w, "lines_h" => lines_h,
                          "lines_v" => lines_v, "dist_x" => dist_x,
                          "dist_y" => dist_y }
    return grid
  end
def draw_grid x , y , h , w , lines_h , lines_v grid = [ ] curr_y = y dist_y = h / ( lines_h + 1 ) lines_h . times do curr_y += dist_y grid << horizontal_separator ( curr_y , x , x + w - 1 ) end curr_x = x dist_x = w / ( lines_v + 1 ) lines_v . times do curr_x += dist_x grid << vertical_separator ( curr_x , y + 1 , y + h ) end state . paint_grid ||= { "x" => x , "y" => y , "h" => h , "w" => w , "lines_h" => lines_h , "lines_v" => lines_v , "dist_x" => dist_x , "dist_y" => dist_y } return grid end
Draws the grid by adding in vertical and horizontal separators.
Draws the grid by adding in vertical and horizontal separators .
# The grid starts off empty. # Calculates the placement and adds horizontal lines or separators into the grid. # start at the bottom of the box # finds distance to place horizontal lines evenly throughout 500 height of grid # increment curr_y by the distance between the horizontal lines # add a separator into the grid # Calculates the placement and adds vertical lines or separators into the grid. # now start at the left of the box # finds distance to place vertical lines evenly throughout 500 width of grid # increment curr_x by the distance between the vertical lines # add separator # paint_grid uses a hash to assign values to keys.
x
y
h
w
lines_h
lines_v