   renderCB: =>
     g.clear(@ctx, @W, @H)
     g.border(@ctx, @W, @H)
+
+
+    for x in [0...@Wi]
+      for y in [0...@Hi]
+        switch @level[x][y].type
+          when 'empty'
+            true
+          when 'program'
+            @renderProgramCell(x, y)
+          when 'obstacle'
+            @renderObstacleCell(x, y)
 
     bot =
       showxi: @botx

    @Wi = Math.floor(@W / g.cell_size)
    @Hi = Math.floor(@H / g.cell_size)
  
  start: ->
    @botx = 5
    @boty = 5
    @botdir = UP.theta

    @program = new Program( [
      'circle',
      'circle',
      'square',
      'diamond',
      'square',
      'circle',
      'diamond'
      ])

    @mapping = new Mapping( [
      'circle',
      'square'
      'diamond'
      'hex'
      ])

    @mapping.commands[0] = new MoveCommand(LEFT)
    @mapping.commands[1] = new MoveCommand(UP)
    #@mapping.commands[2] = new MoveCommand(DOWN)
    @mapping.commands[3] = new MoveCommand(RIGHT)

    @pc = 0
    @execute()

    @startRenderer()
    @startInput()



g = window.dwim_graphics

parseRanges = (ranges_string) ->
  point_list = []

  for range in ranges_string.split(' ')
    [rangex, rangey] =
      for d in range.split(',')
        if d.indexOf('-') == -1
          i = parseInt(d, 10)
          [i, i]
        else
          i = d.split('-')
          [parseInt(i[0], 10), parseInt(i[1], 10)]
    for x in [rangex[0]..rangex[1]]
      for y in [rangey[0]..rangey[1]]
        point_list.push({x:x,y:y})

  point_list

class Dwim
  constructor: (@cnv) ->
    @ctx = @cnv.getContext('2d')
