-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstardates.py
82 lines (68 loc) · 2.46 KB
/
stardates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# ========================================================================
# stardates.py
#
# Description: Convert from common date to Stardate.
#
# https://www.wikihow.com/Calculate-Stardates
#
# Author: Jim Ing
# Date: 2024-08-21
# ========================================================================
import random
import sys
import time
from datetime import datetime
from config import sense
from packages.warp_effects import WarpEffects
from packages.color_names import HTML_COLORS
def is_leap_year(year):
"""Check if a given year is a leap year."""
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
def calculate_stardate(year, month, day, base_system):
"""Calculate the stardate based on the given year, month, day, and system."""
if base_system == "tng":
b = 2005 # base date for TNG
c = 58000.00 # stardate year for TNG
elif base_system == "tos":
b = 2323 # base date for TOS
c = 00000.00 # stardate year for TOS
else:
raise ValueError("Invalid base system. Use 'tng' or 'tos'.")
m_values = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] # month start days
n = 366 if is_leap_year(year) else 365
m = m_values[month - 1]
if is_leap_year(year) and month > 2:
m += 1
stardate = c + (1000 * (year - b)) + ((1000 / n) * (m + day - 1))
return stardate
def display_stardate(stardate):
"""Display the stardate on the Sense HAT with a slower scroll speed."""
sense.show_message(f"Stardate: {stardate:.2f}", scroll_speed=0.08, text_colour=[255, 255, 255])
def main():
base_system = "tng" # Default to TNG system
if len(sys.argv) == 2:
base_system = sys.argv[1].lower()
warp_effect = WarpEffects(sense, speed=1, colors={
'tl': HTML_COLORS.get('white'),
'tr': HTML_COLORS.get('magenta'),
'bl': HTML_COLORS.get('cyan'),
'br': HTML_COLORS.get('orange')
})
print ("To quit, press Ctrl+C")
try:
while True:
today = datetime.today()
year = today.year
month = today.month
day = today.day
stardate = calculate_stardate(year, month, day, base_system)
print(stardate)
warp_effect.fpv()
display_stardate(stardate) # Display the updated stardate
warp_effect.tpv()
time.sleep(5)
except KeyboardInterrupt:
sense.clear()
if __name__ == "__main__":
main()