   import Bitwise
   import WxConstants
 
-  def init(title, width, height, cell_size) do
-    title = to_charlist(title)
-    _create_window(title, width * cell_size, height * cell_size)
+  def init(title, width, height) when is_binary(title) do
+    init to_charlist(title), width, height
+  end
+  def init(title, width, height) do
+    :wx.new()
+    frame = :wxFrame.new(
+      :wx.null, wxID_ANY, title, size: {width, height},
+       style: wxSYSTEM_MENU ||| wxMINIMIZE_BOX  ||| wxCLOSE_BOX ||| wxCAPTION)
+    :wxFrame.show frame
+    frame
   end
 
-  def start_drawing(frame) do
-    # Returns drawing context.
-    :wxBufferedPaintDC.new(frame)
-  end
-
-  def finish_drawing(dc) do
+  def update(frame, bg_color, render) do
+    # Create drawing context.
+    dc = :wxBufferedPaintDC.new(frame)
+    # Clear screen.
+    :wxDC.setBackground dc, brush = :wxBrush.new(bg_color)
+    :wxDC.clear dc
+    :wxBrush.destroy brush
+    # Call the render function.
+    render.(dc)
     # This is required to make the changes visible.
     :wxBufferedPaintDC.destroy dc
-  end
-
-  def clear(dc) do
-    :wxDC.setBackground dc, brush = :wxBrush.new({255, 255, 255})
-    :wxDC.clear dc
-    :wxBrush.destroy brush
   end
 
   def draw_rectangle(dc, color, x, y, width, height) do

     {x3, y1}, {x3, y2}, {x3, y3}]
  end

  def grid_elem(grid, x, y) do
    elem(elem(grid, y), x)
  end

  def render(screen, grid, width, height) do
    context = Screen.start_drawing(screen)
    Screen.clear context
    for y <- 0..(height-1), x <- 0..(width-1), grid_elem(grid, x, y) do
      Screen.draw_rectangle(
        context, @cell_color,
        x * @cell_size, y * @cell_size, @cell_size, @cell_size)
    end
    Screen.finish_drawing(context)
  end
end


    :wxPen.destroy pen
    :wxBrush.destroy brush
  end
end


