import math


def rotate (x, y, deg, clockwise=False):
    """Rotates (`x`, `y`) cartesian coordinates `deg`rees counterclockwise
    (default) or clockwise.  Assumes `(x, y)` are integer coordinates and
    maintains (returns) integer coordinates (i.e. rounds).
    """
    t  = math.radians(360 - deg if clockwise else deg)
    rx = round( x * math.cos(t) - y * math.sin(t) )
    ry = round( x * math.sin(t) + y * math.cos(t) )
    return rx, ry