Calculating direction traveling around a circle? (knowing when to move CW vs CCW)

81 Views Asked by At

I have a point I am animating that is traveling around a compass. The point should always move in the direction of what would be the shortest path. I have something like this at the moment:

step = 1
current = 30
end = 90

if abs(current - end) / 180 > 1
  step *= -1

while current != end
  current += step

  if current < 0
    current += 360

  if current >= 360
    current = mod(current, 360)

  do_animation(current)

This gets me what I want but I was wondering if there was a more efficient and formulaic solution out there?