<commit_before>require_relative '../map'
require_relative '../game_settings'

class GameOfLifeMap < Map

  def initialize(game)
    super(game)
    update_grid
  end

  # defines how user input should be handled to update the game state.
  def process_event(message)
    if message.type == :left_click
      transform_coordinates(message.content)

    end
    #raise "not implemented yet"
  end

  # defines how thicker should update this map.
  def process_ticker
    #raise "not implemented yet"
  end

  private

  def update_grid
    @prev_iter_grid = @grid
  end

  # TODO: think about porting this method to Map
  #
  # from canvas coordinates (clicked at position) to grid coordinates
  # (determine which grid cell has been clicked)
  # @param point [Point2f] canvas coordinates
  # @return [Point2f] (inner) grid coordinates
  def transform_coordinates(point)

    x_frac = (CELL_SIZE.to_f/WIDTH_PIXELS)
    y_frac = (CELL_SIZE.to_f/HEIGHT_PIXELS)

    x_grid = (point.x / (x_frac*WIDTH_PIXELS.to_f)).to_i
    y_grid = (point.y / (y_frac*HEIGHT_PIXELS.to_f)).to_i

    # truncated: TODO report this
    x_grid = WIDTH_PIXELS if x_grid > WIDTH_PIXELS
    y_grid = HEIGHT_PIXELS if y_grid > HEIGHT_PIXELS


    # since there is a border around the grid we have to shift the zero
    grid_p = Point2f.new(x_grid, y_grid).add(Point2f.new(1,1))

    puts "(#{grid_p})"
    grid_p
  end


end<commit_msg>Can pixelwise draw onto canvas<commit_after>require_relative '../map'
require_relative '../game_settings'

class GameOfLifeMap < Map

  def initialize(game)
    super(game)
    update_grid
  end

  # defines how user input should be handled to update the game state.
  def process_event(message)
    if message.type == :left_click
      p = transform_coordinates(message.content)

      field = field_at(p.x,p.y)

      color = (field.color == 'white')? 'green' : 'white'
      set_field_color_at(p.x, p.y, color)
    end
    #raise "not implemented yet"
  end

  # defines how thicker should update this map.
  def process_ticker
    #raise "not implemented yet"
  end

  private

  def update_grid
    @prev_iter_grid = @grid
  end

  # TODO: think about porting this method to Map
  #
  # from canvas coordinates (clicked at position) to grid coordinates
  # (determine which grid cell has been clicked)
  # @param point [Point2f] canvas coordinates
  # @return [Point2f] (inner) grid coordinates
  def transform_coordinates(point)

    x_frac = (CELL_SIZE.to_f/WIDTH_PIXELS)
    y_frac = (CELL_SIZE.to_f/HEIGHT_PIXELS)

    x_grid = (point.x / (x_frac*WIDTH_PIXELS.to_f)).to_i
    y_grid = (point.y / (y_frac*HEIGHT_PIXELS.to_f)).to_i

    # truncated: TODO report this
    x_grid = WIDTH_PIXELS if x_grid > WIDTH_PIXELS
    y_grid = HEIGHT_PIXELS if y_grid > HEIGHT_PIXELS


    # since there is a border around the grid we have to shift the zero
    grid_p = Point2f.new(x_grid, y_grid).add(Point2f.new(1,1))

    puts "(#{grid_p})"
    grid_p
  end


end
{'fraction_non_alphanumeric': 0.08793800539083559, 'fraction_numerical': 0.004043126684636119, 'mean_word_length': 3.3597650513950073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6184833', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1039, 'n_words': 290}