 = Math.atan((loc.y - polygonRotating.y) /
            (loc.x - polygonRotating.x))
            - rotatingLockAngle;

        polygonRotating.startAngle += angle;

        polygonRotating = undefined;
        rotatingLockEngaged = false;
        rotatingLockAngle = 0;
    }

    function startDragging(loc) {
        saveDrawingSurface();
        mousedown.x = loc.x;
        mousedown.y = loc.y;
    }

    // Event handlers................................................

    canvas.onmousedown = function (e