Better color temperature approximation + sine weighted intensity
This commit is contained in:
parent
8c4381f72b
commit
c52c355299
64
clock.py
64
clock.py
|
@ -11,7 +11,7 @@ from kivy.properties import ObjectProperty
|
||||||
import time
|
import time
|
||||||
from sounds import WakeUpSounds
|
from sounds import WakeUpSounds
|
||||||
import json
|
import json
|
||||||
from hsluv import hsluv_to_rgb
|
from hsluv import hsluv_to_rgb, rgb_to_hsluv
|
||||||
|
|
||||||
def is_arm():
|
def is_arm():
|
||||||
if (uname()[4][:3] == 'arm') or (uname()[4][:7] == 'aarch64'):
|
if (uname()[4][:3] == 'arm') or (uname()[4][:7] == 'aarch64'):
|
||||||
|
@ -627,10 +627,66 @@ class MyClockWidget(FloatLayout):
|
||||||
elif intensity > 1:
|
elif intensity > 1:
|
||||||
intensity = 1
|
intensity = 1
|
||||||
|
|
||||||
h = max(0, min(75, (75 - 12) * intensity + 12))
|
# sunlight intensity and color temperature vary with sine function
|
||||||
s = max(0, min(100, 250 - 250 * intensity))
|
intensity = math.sin(2 * math.pi * intensity / 4)
|
||||||
l = 100 * intensity
|
|
||||||
|
|
||||||
|
# from https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html
|
||||||
|
# usable between 1000 and 40000 K
|
||||||
|
|
||||||
|
# we only want color temperatures between 2000 and 6500 K
|
||||||
|
CCT = 2000 + (6500 - 2000) * intensity
|
||||||
|
|
||||||
|
if CCT < 1000:
|
||||||
|
CCT = 1000
|
||||||
|
if CCT > 40000:
|
||||||
|
CCT = 40000
|
||||||
|
|
||||||
|
Temperature = CCT / 100
|
||||||
|
|
||||||
|
if Temperature <= 66:
|
||||||
|
Red = 255
|
||||||
|
else:
|
||||||
|
Red = Temperature - 60
|
||||||
|
Red = 329.698727446 * pow(Red, -0.1332047592)
|
||||||
|
if Red < 0:
|
||||||
|
Red = 0
|
||||||
|
if Red > 255:
|
||||||
|
Red = 255
|
||||||
|
|
||||||
|
if Temperature <= 66:
|
||||||
|
Green = Temperature
|
||||||
|
Green = 99.4708025861 * math.log(Green) - 161.1195681661
|
||||||
|
if Green < 0:
|
||||||
|
Green = 0
|
||||||
|
if Green > 255:
|
||||||
|
Green = 255
|
||||||
|
else:
|
||||||
|
Green = Temperature - 60
|
||||||
|
Green = 288.1221695283 * pow(Green, -0.0755148492)
|
||||||
|
if Green < 0:
|
||||||
|
Green = 0
|
||||||
|
if Green > 255:
|
||||||
|
Green = 255
|
||||||
|
|
||||||
|
if Temperature >= 66:
|
||||||
|
Blue = 255
|
||||||
|
else:
|
||||||
|
if Temperature <= 19:
|
||||||
|
Blue = 0
|
||||||
|
else:
|
||||||
|
Blue = Temperature - 10
|
||||||
|
Blue = 138.5177312231 * math.log(Blue) - 305.0447927307
|
||||||
|
if Blue < 0:
|
||||||
|
Blue = 0
|
||||||
|
if Blue > 255:
|
||||||
|
Blue = 255
|
||||||
|
|
||||||
|
rgb_cct = [Red / 255, Green / 255, Blue / 255]
|
||||||
|
|
||||||
|
# adjust intensity
|
||||||
|
[h, s, l]= rgb_to_hsluv(rgb_cct)
|
||||||
|
|
||||||
|
l = l * intensity
|
||||||
rgb = hsluv_to_rgb([h, s, l])
|
rgb = hsluv_to_rgb([h, s, l])
|
||||||
|
|
||||||
return rgb
|
return rgb
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"theme": "Light",
|
"theme": "Automatic",
|
||||||
"volume": 13,
|
"volume": 1,
|
||||||
"wake_up_sound": "NPO Radio 1",
|
"wake_up_sound": "Birds",
|
||||||
"wake_up_brightness": 4,
|
"wake_up_brightness": 20,
|
||||||
"reading_light_brightness": 13,
|
"reading_light_brightness": 2,
|
||||||
"display_brightness": 13,
|
"display_brightness": 20,
|
||||||
"alarm_activated": true,
|
"alarm_activated": false,
|
||||||
"alarm_time_hour": 6,
|
"alarm_time_hour": 9,
|
||||||
"alarm_time_minute": 57
|
"alarm_time_minute": 9
|
||||||
}
|
}
|
Loading…
Reference in New Issue