@@ -9,6 +9,8 @@ Author: Joey Hoer
99
1010load ("render.star" , "render" )
1111load ("schema.star" , "schema" )
12+ load ("math.star" , "math" )
13+ load ("re.star" , "re" )
1214load ("time.star" , "time" )
1315load ("sunrise.star" , "sunrise" )
1416load ("encoding/base64.star" , "base64" )
@@ -24,8 +26,18 @@ DEFAULT_TIMEZONE = "US/Eastern"
2426DEFAULT_IS_24_HOUR_FORMAT = True
2527DEFAULT_HAS_LEADING_ZERO = False
2628DEFAULT_HAS_FLASHING_SEPERATOR = True
27- DEFAULT_COLOR_DAYTIME = "#fff" # White
28- DEFAULT_COLOR_NIGHTTIME = "#fff" # White
29+
30+ # White
31+ DEFAULT_COLOR_RED_DAYTIME = "255"
32+ DEFAULT_COLOR_GREEN_DAYTIME = "255"
33+ DEFAULT_COLOR_BLUE_DAYTIME = "255"
34+ DEFAULT_LIGHTNESS_DAYTIME = 100
35+
36+ # Red
37+ DEFAULT_COLOR_RED_NIGHTTIME = "255"
38+ DEFAULT_COLOR_GREEN_NIGHTTIME = "0"
39+ DEFAULT_COLOR_BLUE_NIGHTTIME = "0"
40+ DEFAULT_LIGHTNESS_NIGHTTIME = 100
2941
3042# Constants
3143TTL = 21600 # 6 hours
@@ -77,7 +89,9 @@ iVBORw0KGgoAAAANSUhEUgAAAAQAAAAOAQAAAAAgEYC1AAAAAnRSTlMAAQGU/a4AAAAPSURBVHgBY0g
7789AQzQAEQUAH5wCQbfIiwYAAAAASUVORK5CYII=
7890""" )
7991
80- DEGREE = 0.01745329251
92+ # Convert RGB tuple to hex
93+ def rgb_to_hex (r , g , b ):
94+ return "#" + str ("%x" % ((1 << 24 ) + (r << 16 ) + (g << 8 ) + b ))[1 :]
8195
8296# It would be easier to use a custom font, but we can use images instead.
8397# The images have a black background and transparent foreground. This
@@ -150,8 +164,18 @@ def main(config):
150164 is_24_hour_format = config .bool ("is_24_hour_format" , DEFAULT_IS_24_HOUR_FORMAT )
151165 has_leading_zero = config .bool ("has_leading_zero" , DEFAULT_HAS_LEADING_ZERO )
152166 has_flashing_seperator = config .bool ("has_flashing_seperator" , DEFAULT_HAS_FLASHING_SEPERATOR )
153- color_daytime = config .get ("color_daytime" , DEFAULT_COLOR_DAYTIME )
154- color_nighttime = config .get ("color_nighttime" , DEFAULT_COLOR_NIGHTTIME )
167+
168+ # Set daytime color
169+ color_red_daytime = config .get ("color_red_daytime" , DEFAULT_COLOR_RED_DAYTIME );
170+ color_green_daytime = config .get ("color_green_daytime" , DEFAULT_COLOR_GREEN_DAYTIME );
171+ color_blue_daytime = config .get ("color_blue_daytime" , DEFAULT_COLOR_BLUE_DAYTIME );
172+ color_daytime = rgb_to_hex (int (color_red_daytime ), int (color_green_daytime ), int (color_blue_daytime ))
173+
174+ # Set nighttime color
175+ color_red_nighttime = config .get ("color_red_nighttime" , DEFAULT_COLOR_RED_NIGHTTIME )
176+ color_green_nighttime = config .get ("color_green_nighttime" , DEFAULT_COLOR_GREEN_NIGHTTIME )
177+ color_blue_nighttime = config .get ("color_blue_nighttime" , DEFAULT_COLOR_BLUE_NIGHTTIME )
178+ color_nighttime = rgb_to_hex (int (color_red_nighttime ), int (color_green_nighttime ), int (color_blue_nighttime ))
155179
156180 frames = []
157181 print_time = current_time
@@ -165,11 +189,14 @@ def main(config):
165189 duration = 1 # in minutes; 1440 = 24 hours
166190 for i in range (0 , duration ):
167191 # Set different color during day and night
192+ # color = lightness(color_nighttime, lightness_nighttime)
168193 color = color_nighttime
169194 if rise == None or set == None :
170195 # Antarctica, north pole, etc.
196+ # color = lightness(color_daytime, lightness_daytime)
171197 color = color_daytime
172198 elif now > rise and now < set :
199+ # color = lightness(color_daytime, lightness_daytime)
173200 color = color_daytime
174201 frames .append (get_time_image (print_time , color , is_24_hour_format = is_24_hour_format , has_leading_zero = has_leading_zero , has_seperator = True ))
175202
@@ -202,16 +229,9 @@ def main(config):
202229 )
203230
204231def get_schema ():
205- colors = [
206- schema .Option (display = "White" , value = "#fff" ),
207- schema .Option (display = "Red" , value = "#f00" ),
208- schema .Option (display = "Dark Red" , value = "#200" ),
209- schema .Option (display = "Green" , value = "#0f0" ),
210- schema .Option (display = "Blue" , value = "#00f" ),
211- schema .Option (display = "Yellow" , value = "#ff0" ),
212- schema .Option (display = "Cyan" , value = "#0ff" ),
213- schema .Option (display = "Magenta" , value = "#f0f" ),
214- ]
232+ zeroTo255 = []
233+ for n in range (256 ):
234+ zeroTo255 .append (schema .Option (display = str (n ), value = str (n )));
215235
216236 return schema .Schema (
217237 version = "1" ,
@@ -244,20 +264,52 @@ def get_schema():
244264 default = DEFAULT_HAS_FLASHING_SEPERATOR ,
245265 ),
246266 schema .Dropdown (
247- id = "color_daytime" ,
267+ id = "color_red_daytime" ,
268+ icon = "sun" ,
269+ name = "Daytime red RGB value" ,
270+ desc = "The red RGB color value to use during daytime." ,
271+ options = zeroTo255 ,
272+ default = DEFAULT_COLOR_RED_DAYTIME ,
273+ ),
274+ schema .Dropdown (
275+ id = "color_green_daytime" ,
276+ icon = "sun" ,
277+ name = "Daytime green RGB value" ,
278+ desc = "The green RGB color value to use during daytime." ,
279+ options = zeroTo255 ,
280+ default = DEFAULT_COLOR_GREEN_DAYTIME ,
281+ ),
282+ schema .Dropdown (
283+ id = "color_blue_daytime" ,
248284 icon = "sun" ,
249- name = "Daytime color" ,
250- desc = "The color to display in the daytime." ,
251- options = colors ,
252- default = DEFAULT_COLOR_DAYTIME ,
285+ name = "Daytime blue RGB value" ,
286+ desc = "The blue RGB color value to use during daytime." ,
287+ options = zeroTo255 ,
288+ default = DEFAULT_COLOR_BLUE_DAYTIME ,
289+ ),
290+ schema .Dropdown (
291+ id = "color_red_nighttime" ,
292+ icon = "moon" ,
293+ name = "Nighttime red RGB value" ,
294+ desc = "The red RGB color value to use during nighttime." ,
295+ options = zeroTo255 ,
296+ default = DEFAULT_COLOR_RED_NIGHTTIME ,
297+ ),
298+ schema .Dropdown (
299+ id = "color_green_nighttime" ,
300+ icon = "moon" ,
301+ name = "Nighttime green RGB value" ,
302+ desc = "The green RGB color value to use during nighttime." ,
303+ options = zeroTo255 ,
304+ default = DEFAULT_COLOR_GREEN_NIGHTTIME ,
253305 ),
254306 schema .Dropdown (
255- id = "color_nighttime " ,
307+ id = "color_blue_nighttime " ,
256308 icon = "moon" ,
257- name = "Nighttime color " ,
258- desc = "The color to display at night ." ,
259- options = colors ,
260- default = DEFAULT_COLOR_NIGHTTIME ,
309+ name = "Nighttime blue RGB value " ,
310+ desc = "The blue RGB color value to use during nighttime ." ,
311+ options = zeroTo255 ,
312+ default = DEFAULT_COLOR_BLUE_NIGHTTIME ,
261313 ),
262314 ],
263315 )
0 commit comments