     # Text
     context.fillStyle = 'white'
     contextRotationAngle = Math.atan(y1 / x1) + (Math.PI / (if x1<0 then 2 else -2))
-    console.log contextRotationAngle
     context.translate (canvas.width/2), (canvas.height/2)
     context.rotate contextRotationAngle
     context.translate (canvas.width/-2), (canvas.height/-2)

    context.textAlign = "center"
    context.textBaseline = "middle"

  resizeCanvas()

  drawCanvas = (x1,y1,x2,y2,angle) ->

    # Get local copies of canvas config params
    centerX = window.app.centerX

    context.rotate -1 * contextRotationAngle
    context.translate (canvas.width/-2), (canvas.height/-2)

  resizeCanvas()

  $(window).on "deviceorientation", (e) ->
    x = e.originalEvent.beta
    y = e.originalEvent.gamma
    z = e.originalEvent.alpha

    # Calculate the angle from flat, which we can use later to draw different
    # compass representations which depend on the device angle.
    angleFromFlat = Math.round(Math.sqrt Math.pow(y,2) + Math.pow(x,2))
    drawCircles x, y, z, angleFromFlat


  $(window).on "resize", resizeCanvas
