 
   if bugs.turns % 10 == 0
     stats = bugs.names.map((name) -> bugs.stats[name])
-    make_chart '#jitterbug_progress_chart_svg', stats, 1000, bugs.count
-
-  if bugs.turns < 1000
+    make_chart '#jitterbug_progress_chart_svg', stats, bugs.max_turns, bugs.count
+
+  if bugs.turns < bugs.max_turns
     bugs.turns += 1
     setTimeout((-> next_turn bugs, canvas), 50)
 
-empty_grid = ->
+starting_bugs = (bug_size, width, height, max_turns) ->
   grid = []
 
-  for x in [0..59]
+  for x in [0..(width - 1)]
     grid[x] = []
-    for y in [0..39]
+    for y in [0..(height - 1)]
       grid[x][y] = null
 
-  grid
-
-starting_bugs = ->
   bugs =
-    grid:        empty_grid()
+    grid:        grid
     colors:      {}
     next_serial: 0
     stats:       {}

    next_color:  ['black', 'yellow', 'blue', 'grey', 'pink', 'green', 'red']
    turns:       0
    count:       0

  for i in [0..10]
    add_bug bugs, 'fly_trap', create_fly_trap

  for i in [0..10]
    add_bug bugs, 'moth1', create_moth

  for i in [0..10]
    add_bug bugs, 'moth2', create_moth

  bugs

turn_bug = (bug, offset) ->
  bug.direction = (((bug.direction + offset) % 4) + 4) % 4

add_bug_to_canvas = (canvas, bug, bug_size) ->
  x   = bug.location.x * bug_size
  y   = bug.location.y * bug_size
  pos = switch bug.direction
    when 0 then left: x,            top: y,            angle:   0
    when 1 then left: x + bug_size, top: y,            angle:  90
    when 2 then left: x + bug_size, top: y + bug_size, angle: 180
    when 3 then left: x,            top: y + bug_size, angle: 270

  if bug.prev_name == bug.name
    if bug.canvas_img
