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
|
# -*- python -*-
import os
# Geographical coodinates.
try:
with open(os.getenv("XDG_CONFIG_HOME") + "/geolocation", 'rb') as file:
latitude, longitude = file.read().split(b'\n')[0].decode('utf-8', 'replace').split(' ')
latitude, longitude = float(latitude), float(longitude)
except:
with open("/etc/geolocation", 'rb') as file:
latitude, longitude = file.read().split(b'\n')[0].decode('utf-8', 'replace').split(' ')
latitude, longitude = float(latitude), float(longitude)
# The colour temperature at day and at night.
temperature_day, temperature_night = 5500, 3500
# Get current time.
now = epoch()
now_m = now - 1
now_p = now + 1
now_d = now_p - now_m
now = epoch_to_julian_centuries(now)
now_m = epoch_to_julian_centuries(now_m)
now_p = epoch_to_julian_centuries(now_p)
# The visibility of the Sun.
dayness = sun(latitude, longitude, now)
dayness_m = sun(latitude, longitude, now_m)
dayness_p = sun(latitude, longitude, now_p)
dayness_d = (dayness_p - dayness_m) / now_d
# The Sun's elevation.
elevation = solar_elevation(latitude, longitude, now)
elevation_m = solar_elevation(latitude, longitude, now_m)
elevation_p = solar_elevation(latitude, longitude, now_p)
elevation_d = (elevation_p - elevation_m) / now_d
# Calculation of the colour temperature.
temperature = temperature_day * dayness + temperature_night * (1 - dayness)
temperature_m = temperature_day * dayness_m + temperature_night * (1 - dayness_m)
temperature_p = temperature_day * dayness_p + temperature_night * (1 - dayness_p)
temperature_d = (temperature_p - temperature_m) / now_d
# Calculate the whitepoint with adjusted colour temperature.
whitepoint = divide_by_maximum(cmf_10deg(temperature))
whitepoint = [str(int(c * 255 + 0.5)) for c in whitepoint]
whitepoint = ';'.join(whitepoint)
# Convert derivative to per minutes from per seconds.
temperature_d *= 60
elevation_d *= 60
dayness_d *= 60
# Print information.
dayness *= 100
dayness_d *= 100
output = '\033[38;2;%sm%i\033[0mK %.1fK/m %.1f° %.2f°/m %.0f%% %.1f%%/m'
output %= (whitepoint, temperature, temperature_d, elevation, elevation_d, dayness, dayness_d)
print(output)
|