Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- There are 60 minutes on an analog clock.
- There are 12 hours on an analog clock.
- Also note that if it's 5:30, the hours hand isn't on the 5. It's halfway between 5 and 6.
- There are also 60 minutes between each hour, of which there are 12.
- Hence, the math used here. Ask if you need explanation.
- --]]
- local function findAngle(hours, minutes)
- -- The angle of the hours hand
- local hAngle = (hours / 12) * 360 + (minutes / (12 * 60)) * 360
- -- The angle of the minutes hand
- local mAngle = (minutes / 60) * 360
- -- The angle between them - absolute value
- local angle = math.abs(hAngle - mAngle)
- -- There's a larger angle and a smaller angle - return the smallest
- return angle > 180 and 360 - angle or angle
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement