Skip to content

Instantly share code, notes, and snippets.

@NicolaM94
Created November 27, 2023 11:00
Show Gist options
  • Save NicolaM94/6e0e0ffa41a3da006cd011e6f783163d to your computer and use it in GitHub Desktop.
Save NicolaM94/6e0e0ffa41a3da006cd011e6f783163d to your computer and use it in GitHub Desktop.
Clock position and hands angles degree
class ClockPosition ():
def __init__(self,hh,mm):
self.hh = hh
self.mm = mm
self.mmdegree = self.mm * 6
self.hhdegree = (self.hh % 12) * 30 + self.mm * 0.5
def calculateInternalAngle (self):
# Calculates the absolute value of the angle
angleOne = self.mmdegree - self.hhdegree
if angleOne < 0:
angleOne = angleOne * (-1)
# Calculates the other face of the angle
angleTwo = 360 - angleOne
# Returns the smallest one
if angleOne < angleTwo:
return angleOne
return angleTwo
with open("clockpositions.txt","w") as file:
for hh in range(0,24):
for mm in range(0,60):
ck = ClockPosition(hh,mm).calculateInternalAngle()
file.write(f"HH: {hh}\tMM: {mm}\tAngle: {ck}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment