     elem(elem(grid, y), x)
   end
 
-  def render(dc, grid: grid, width: width, height: height) do
+  def render(dc, grid, width, height) do
     for y <- 0..(height-1) do
       for x <- 0..(width-1) do
         if grid_elem(grid, x, y) do

    frame = :wxFrame.new(
      :wx.null, wxID_ANY, title, size: {width, height},
       style: wxSYSTEM_MENU ||| wxMINIMIZE_BOX  ||| wxCLOSE_BOX ||| wxCAPTION)
    current = self()
    :wxPanel.connect frame, :paint, [callback: fn (event, object) ->
      send current, {:wx, event, object}
    end]
    :wxFrame.show frame
    frame
  end

  def _process_messages(frame, renderer, data \\ nil) do
    next_data =
      receive do
        {:wx, _, _} -> data
        {:update, new_data} -> new_data
      end

    dc = :wxBufferedPaintDC.new(frame)
    # Clear screen.
    :wxDC.setBackground dc, brush = :wxBrush.new({255, 255, 255})
    :wxDC.clear dc
    :wxBrush.destroy brush
    # Call the render function.
    if next_data != nil, do: renderer.(dc, next_data)
    :wxBufferedPaintDC.destroy dc

    _process_messages frame, renderer, next_data
  end
end


defmodule Screen do
  import Bitwise

  def init(title, width, height, cell_size) do
    title = to_charlist(title)
    _create_window(title, width * cell_size, height * cell_size)
  end

  def update(frame, renderer) do
    dc = :wxBufferedPaintDC.new(frame)
    # Clear screen.
    :wxDC.setBackground dc, brush = :wxBrush.new({255, 255, 255})
    :wxDC.clear dc
    :wxBrush.destroy brush
    # Call the render function.
    renderer.(dc)
    :wxBufferedPaintDC.destroy dc
  end

  def draw_rectangle(dc, color, x, y, width, height) do
