Skip to content

Commit cb30e16

Browse files
committed
Updating bigclock to use RGB color values rather than a predefined list of colors for full customizability
1 parent 332290b commit cb30e16

File tree

1 file changed

+72
-25
lines changed

1 file changed

+72
-25
lines changed

apps/bigclock/big_clock.star

Lines changed: 72 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Author: Joey Hoer
99

1010
load("render.star", "render")
1111
load("schema.star", "schema")
12+
load("math.star", "math")
13+
load("re.star", "re")
1214
load("time.star", "time")
1315
load("sunrise.star", "sunrise")
1416
load("encoding/base64.star", "base64")
@@ -24,8 +26,16 @@ DEFAULT_TIMEZONE = "US/Eastern"
2426
DEFAULT_IS_24_HOUR_FORMAT = True
2527
DEFAULT_HAS_LEADING_ZERO = False
2628
DEFAULT_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+
35+
# Red
36+
DEFAULT_COLOR_RED_NIGHTTIME = "255"
37+
DEFAULT_COLOR_GREEN_NIGHTTIME = "0"
38+
DEFAULT_COLOR_BLUE_NIGHTTIME = "0"
2939

3040
# Constants
3141
TTL = 21600 # 6 hours
@@ -77,7 +87,9 @@ iVBORw0KGgoAAAANSUhEUgAAAAQAAAAOAQAAAAAgEYC1AAAAAnRSTlMAAQGU/a4AAAAPSURBVHgBY0g
7787
AQzQAEQUAH5wCQbfIiwYAAAAASUVORK5CYII=
7888
""")
7989

80-
DEGREE = 0.01745329251
90+
# Convert RGB tuple to hex
91+
def rgb_to_hex(r, g, b):
92+
return "#" + str("%x" % ((1 << 24) + (r << 16) + (g << 8) + b))[1:]
8193

8294
# It would be easier to use a custom font, but we can use images instead.
8395
# The images have a black background and transparent foreground. This
@@ -150,8 +162,18 @@ def main(config):
150162
is_24_hour_format = config.bool("is_24_hour_format", DEFAULT_IS_24_HOUR_FORMAT)
151163
has_leading_zero = config.bool("has_leading_zero", DEFAULT_HAS_LEADING_ZERO)
152164
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)
165+
166+
# Set daytime color
167+
color_red_daytime = config.get("color_red_daytime", DEFAULT_COLOR_RED_DAYTIME)
168+
color_green_daytime = config.get("color_green_daytime", DEFAULT_COLOR_GREEN_DAYTIME)
169+
color_blue_daytime = config.get("color_blue_daytime", DEFAULT_COLOR_BLUE_DAYTIME)
170+
color_daytime = rgb_to_hex(int(color_red_daytime), int(color_green_daytime), int(color_blue_daytime))
171+
172+
# Set nighttime color
173+
color_red_nighttime = config.get("color_red_nighttime", DEFAULT_COLOR_RED_NIGHTTIME)
174+
color_green_nighttime = config.get("color_green_nighttime", DEFAULT_COLOR_GREEN_NIGHTTIME)
175+
color_blue_nighttime = config.get("color_blue_nighttime", DEFAULT_COLOR_BLUE_NIGHTTIME)
176+
color_nighttime = rgb_to_hex(int(color_red_nighttime), int(color_green_nighttime), int(color_blue_nighttime))
155177

156178
frames = []
157179
print_time = current_time
@@ -202,16 +224,9 @@ def main(config):
202224
)
203225

204226
def 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-
]
227+
zeroTo255 = []
228+
for n in range(256):
229+
zeroTo255.append(schema.Option(display = str(n), value = str(n)))
215230

216231
return schema.Schema(
217232
version = "1",
@@ -244,20 +259,52 @@ def get_schema():
244259
default = DEFAULT_HAS_FLASHING_SEPERATOR,
245260
),
246261
schema.Dropdown(
247-
id = "color_daytime",
262+
id = "color_red_daytime",
263+
icon = "sun",
264+
name = "Daytime red RGB value",
265+
desc = "The red RGB color value to use during daytime.",
266+
options = zeroTo255,
267+
default = DEFAULT_COLOR_RED_DAYTIME,
268+
),
269+
schema.Dropdown(
270+
id = "color_green_daytime",
271+
icon = "sun",
272+
name = "Daytime green RGB value",
273+
desc = "The green RGB color value to use during daytime.",
274+
options = zeroTo255,
275+
default = DEFAULT_COLOR_GREEN_DAYTIME,
276+
),
277+
schema.Dropdown(
278+
id = "color_blue_daytime",
248279
icon = "sun",
249-
name = "Daytime color",
250-
desc = "The color to display in the daytime.",
251-
options = colors,
252-
default = DEFAULT_COLOR_DAYTIME,
280+
name = "Daytime blue RGB value",
281+
desc = "The blue RGB color value to use during daytime.",
282+
options = zeroTo255,
283+
default = DEFAULT_COLOR_BLUE_DAYTIME,
284+
),
285+
schema.Dropdown(
286+
id = "color_red_nighttime",
287+
icon = "moon",
288+
name = "Nighttime red RGB value",
289+
desc = "The red RGB color value to use during nighttime.",
290+
options = zeroTo255,
291+
default = DEFAULT_COLOR_RED_NIGHTTIME,
292+
),
293+
schema.Dropdown(
294+
id = "color_green_nighttime",
295+
icon = "moon",
296+
name = "Nighttime green RGB value",
297+
desc = "The green RGB color value to use during nighttime.",
298+
options = zeroTo255,
299+
default = DEFAULT_COLOR_GREEN_NIGHTTIME,
253300
),
254301
schema.Dropdown(
255-
id = "color_nighttime",
302+
id = "color_blue_nighttime",
256303
icon = "moon",
257-
name = "Nighttime color",
258-
desc = "The color to display at night.",
259-
options = colors,
260-
default = DEFAULT_COLOR_NIGHTTIME,
304+
name = "Nighttime blue RGB value",
305+
desc = "The blue RGB color value to use during nighttime.",
306+
options = zeroTo255,
307+
default = DEFAULT_COLOR_BLUE_NIGHTTIME,
261308
),
262309
],
263310
)

0 commit comments

Comments
 (0)