Last active
August 29, 2015 14:03
-
-
Save eric-wood/829cf6c4aac46142fa4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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