Skip to content

Instantly share code, notes, and snippets.

@eric-wood
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save eric-wood/829cf6c4aac46142fa4a to your computer and use it in GitHub Desktop.

Select an option

Save eric-wood/829cf6c4aac46142fa4a to your computer and use it in GitHub Desktop.
# Direction can either be a Fixnum for number of degrees,
# or a symbol for the direction (:left, :right)
def rotate(direction, speed: DEFAULT_SPEED)
# handle symbols...
case direction
when :left
direction = -90
when :right
direction = 90
end
circumfrence = 2 * Math::PI * RADIUS
# based on the angle, this is how far we need to turn
Math.abs(distance = (circumfrence / 360) * direction)
direction < 0 ? spin_left(speed) : spin_right(speed)
duration = distance / speed
sleep(duration)
halt
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment