     [x1 - x2, y1 - y2]
   mul: ([x, y], c) ->
     [x * c, y * c]
+  polarToVector: (theta, length) ->
+    [ cos(theta) * length, sin(theta) * length ]
 
 class Ship
   constructor: (x, y, @theta= HALF_PI * 3) ->

      @theta -= PI/30

    if @thrust = controls.up
      a = MAX_THRUST / SHIP_MASS
      deltaX = a * cos(@theta) * dt
      deltaY = a * sin(@theta) * dt
      @velocity = Vec.add @velocity, [deltaX, deltaY]

    @position = Vec.add @position, Vec.mul(@velocity, dt)


    ctx.translate 0, yEdge * ctx.height
    drawFn()
    ctx.translate 0, -yEdge * ctx.height

ctx.update = ->
  ship.update ctx.dt / 1000, controls

ctx.draw = ->
  drawWrapped ship.nearEdges(ctx), -> ship.draw(ctx)
  stats.update()

ctx.keyup = (e) ->
  switch e.keyCode
