From 1aace48a2102218cc02b64cc76d20c9771b3bb64 Mon Sep 17 00:00:00 2001 From: explorer9957 <364212876+explorer9957@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:44:29 -0500 Subject: [PATCH 1/2] Add Xmas Scenes: daily Christmas countdown with a new scene each day --- apps/xmasscenes/manifest.yaml | 15 + apps/xmasscenes/xmasscenes.star | 1517 +++++++++++++++++++++++++++++++ apps/xmasscenes/xmasscenes.webp | Bin 0 -> 4158 bytes 3 files changed, 1532 insertions(+) create mode 100644 apps/xmasscenes/manifest.yaml create mode 100644 apps/xmasscenes/xmasscenes.star create mode 100644 apps/xmasscenes/xmasscenes.webp diff --git a/apps/xmasscenes/manifest.yaml b/apps/xmasscenes/manifest.yaml new file mode 100644 index 000000000..488010aee --- /dev/null +++ b/apps/xmasscenes/manifest.yaml @@ -0,0 +1,15 @@ +--- +id: xmasscenes +name: Xmas Scenes +summary: Daily Christmas countdown +desc: Counts down the days to Christmas with a different animated pixel-art scene for every day from 45 days out, then a Merry Christmas card on Dec 25. Hidden outside the season you choose. +author: explorer9957 +fileName: xmasscenes.star +packageName: xmasscenes +recommendedInterval: 60 +category: lifestyle +tags: + - holiday + - christmas + - countdown + - animation diff --git a/apps/xmasscenes/xmasscenes.star b/apps/xmasscenes/xmasscenes.star new file mode 100644 index 000000000..fc522e25a --- /dev/null +++ b/apps/xmasscenes/xmasscenes.star @@ -0,0 +1,1517 @@ +""" +Christmas Countdown — days until Christmas, with a different pixel-art +animation for each day. + +Left: the number of days to go. Right: a 40x32 scene picked by the number +(45 = mittens on a clothesline ... 1 = Santa crossing the moon). On Christmas Day the +whole screen becomes a "MERRY CHRISTMAS" card. Outside the window set by +"Show from" the app returns no frames and Tronbyt skips the card. +""" + +load("math.star", "math") +load("render.star", "render") +load("schema.star", "schema") +load("time.star", "time") + +WIDTH = 64 +HEIGHT = 32 +PANEL_W = 24 # number panel +W = 40 # scene width +H = 32 +NF = 32 # frames per loop (32 = one full fall of the screen at 1px/frame) +FRAME_MS = 110 + +RED = "#E02020" +DARK_RED = "#801010" +GREEN = "#20A040" +DARK_GREEN = "#0C5A20" +GOLD = "#FFC000" +WHITE = "#E8F0FF" +SNOW = "#B8C8E8" +BROWN = "#7A4A20" +DARK_BROWN = "#4A2A10" +SKIN = "#F0B080" +GRAY = "#606878" +LIGHTS = ["#FF3030", "#30E050", "#3080FF", "#FFD000", "#FF60D0"] + +# ------------------------------------------------------------ drawing helpers + +def rnd(i, m): + """Deterministic pseudo-random int in [0, m).""" + return ((i * 1103515245 + 12345) // 65536) % m + +def run_box(n, c): + if c == None: + return render.Box(width = n, height = 1) + return render.Box(width = n, height = 1, color = c) + +def raster(x0, y0, w, h, fn): + """Draw a w x h area at (x0, y0) of the scene; fn(x, y) gives a color or + None (transparent) in local coordinates. Clipped to the scene.""" + cx0 = max(0, -x0) + cx1 = min(w, W - x0) + if cx1 <= cx0: + return None + rows = [] + top = None + for y in range(h): + if y0 + y < 0 or y0 + y >= H: + continue + if top == None: + top = y0 + y + runs = [] + cur = None + n = 0 + for x in range(cx0, cx1): + c = fn(x, y) + if n > 0 and c == cur: + n += 1 + else: + if n > 0: + runs.append(run_box(n, cur)) + cur = c + n = 1 + runs.append(run_box(n, cur)) + rows.append(render.Row(children = runs)) + if top == None: + return None + return render.Padding(pad = (max(x0, 0), top, 0, 0), child = render.Column(children = rows)) + +def sprite(rows, pal, x, y): + """Character-art sprite. Characters missing from pal are transparent.""" + w = max([len(r) for r in rows]) + + def fn(xx, yy): + row = rows[yy] + if xx >= len(row): + return None + return pal.get(row[xx]) + + return raster(x, y, w, len(rows), fn) + +def rect(x, y, w, h, c): + x0 = max(x, 0) + y0 = max(y, 0) + x1 = min(x + w, W) + y1 = min(y + h, H) + if x1 <= x0 or y1 <= y0: + return None + return render.Padding(pad = (x0, y0, 0, 0), child = render.Box(width = x1 - x0, height = y1 - y0, color = c)) + +def px(x, y, c): + return rect(x, y, 1, 1, c) + +def disc(cx, cy, r, fn): + """Filled circle; fn(dx, dy) gives the color at offset from the center.""" + + def f(x, y): + dx = x - r + dy = y - r + if dx * dx + dy * dy <= r * r + r: + return fn(dx, dy) + return None + + return raster(cx - r, cy - r, 2 * r + 1, 2 * r + 1, f) + +def line(x0, y0, x1, y1, c): + n = max(abs(x1 - x0), abs(y1 - y0)) + out = [] + for i in range(n + 1): + t = i / n if n else 0 + out.append(px(int(x0 + (x1 - x0) * t + 0.5), int(y0 + (y1 - y0) * t + 0.5), c)) + return out + +def snow(f, count, seed, speed = 1, color = WHITE, drift = True): + """Falling flakes that loop seamlessly over NF frames (speed 1 or 2).""" + out = [] + for i in range(count): + x = rnd(seed + i * 7, W) + y = (rnd(seed + i * 13 + 5, H) + f * speed) % H + if drift: + x = (x + ((f + i * 3) // 8) % 2) % W + out.append(px(x, y, color)) + return out + +def twinkles(f, count, seed, ymax = H, colors = ["#FFFFFF", "#8090C0", "#404870"]): + out = [] + for i in range(count): + phase = (f + rnd(seed + i, NF)) % 8 + c = colors[0] if phase < 2 else (colors[1] if phase < 5 else colors[2]) + out.append(px(rnd(seed + i * 31, W), rnd(seed + i * 17 + 3, ymax), c)) + return out + +def ground(y, c = SNOW): + return rect(0, y, W, H - y, c) + +def scene(children): + """Stack the scene's layers on a black 40x32 canvas, back to front.""" + flat = [] + for c in children: + if type(c) == "list": + flat.extend([x for x in c if x != None]) + elif c != None: + flat.append(c) + return render.Stack(children = [render.Box(width = W, height = H)] + flat) + +def iround(v): + return int(math.floor(v + 0.5)) + +def wave(f, period, amp): + return int(math.sin(2 * math.pi * f / period) * amp + (0.5 if amp > 0 else 0)) + +# ----------------------------------------------------------------- sprites + +TREE_SMALL = [ + "...G...", + "..GGG..", + ".GGGGG.", + "..GGG..", + ".GGGGG.", + "GGGGGGG", + "...T...", +] + +# Big tree; a-d are ornaments/lights, recolored per frame. +TREE_BIG = [ + ".......G.......", + "......GGG......", + ".....GaGGG.....", + "....GGGGbGG....", + "......GGG......", + ".....GGGcG.....", + "....GdGGGGG....", + "...GGGGGaGGG...", + "..GGbGGGGGGdG..", + ".....GGGGG.....", + "....GGcGGGG....", + "...GGGGGGbGG...", + "..GaGGGGGGGGG..", + ".GGGGGdGGGGcGG.", + "GGbGGGGGGaGGGGG", + "......TTT......", + "......TTT......", +] + +STAR_SMALL = [ + "..Y..", + ".YYY.", + "YYYYY", + ".Y.Y.", +] + +STAR_BIG = [ + ".......Y.......", + ".......Y.......", + "......YYY......", + "......YYY......", + ".....YYYYY.....", + "YYYYYYYYYYYYYYY", + ".YYYYYYYYYYYYY.", + "..YYYYYYYYYYY..", + "...YYYYYYYYY...", + "....YYYYYYY....", + "....YYYYYYY....", + "...YYYY.YYYY...", + "...YYY...YYY...", + "..YYY.....YYY..", + "..Y.........Y..", +] + +REINDEER = [ + "......t.t", + ".......t.", + "......BBB", + "BBBBBBBBn", + "BBBBBBB..", + "B.B..B.B.", +] + +SLEIGH = [ + "....RRW.....", + "...RRRR.....", + "...SSSS.....", + "...WWWW.....", + "RRRRRRRRR..Y", + ".RRRRRRRRRYY", + "..YYYYYYYY..", +] + +COOKIE = [ + ".kkkkk.", + "kkckkkk", + "kkkkkck", + "kckkkkk", + ".kkkkk.", +] + +COOKIE_BITTEN = [ + ".kkk...", + "kkck...", + "kkkkk..", + "kckkkkk", + ".kkkkk.", +] + +STOCKING = [ + "WWWWWWW...", + "WWWWWWW...", + ".RRRRR....", + ".RRGRR....", + ".RRRRR....", + ".RRRRG....", + ".RRRRR....", + ".RRRRRR...", + ".RRGRRRRR.", + "..RRRRRRRR", + "...RRRRRRR", + "....RRRRR.", +] + +REINDEER_HEAD = [ + "t..t.........t..t", + ".t.t.t.....t.t.t.", + "..ttt.......ttt..", + "...t.........t...", + "...tt.......tt...", + "....t.......t....", + "...EBBBBBBBBBE...", + "..EEBBBBBBBBBEE..", + ".....BBBBBBB.....", + "....BBwBBBwBB....", + "....BBkBBBkBB....", + ".....BBBBBBB.....", + ".....BBBBBBB.....", + "......lllll......", + "......lllll......", + ".......lll.......", +] + +GINGER = [ + "....ggg....", + "...ggggg...", + "...gwgwg...", + "...ggggg...", + "...gwwwg...", + "....ggg....", + "ggggggggggg", + "gwgggrgggwg", + "...ggggg...", + "...ggrgg...", + "...ggggg...", + "..ggg.ggg..", + ".ggg...ggg.", + ".gwg...gwg.", +] + +SNOWMAN = [ + "....kkkkk....", + "....kkkkk....", + "....kRRRk....", + "..kkkkkkkkk..", + "....WWWWW....", + "...WWeWeWW...", + "...WWWOOWW...", + "...WWWWWWW...", + "...RRRRRRR...", + "...WWWWWRWW..", + "..WWWWeWRWWW.", + ".WWWWWWWWWWW.", + ".WWWWWeWWWWW.", + ".WWWWWWWWWWW.", + "..WWWWWWWWW..", + ".WWWWWWWWWWW.", + "WWWWWWWWWWWWW", + "WWWWWWeWWWWWW", + "WWWWWWWWWWWWW", + ".WWWWWWWWWWW.", + "..WWWWWWWWW..", +] + +BELL = [ + "....Y....", + "...YYY...", + "..YYYYY..", + "..YYYYY..", + "..YYYYY..", + ".YYYYYYY.", + "YYYYYYYYY", + "....o....", +] + +NOTE = [ + "..W", + "..W", + "..W", + "WWW", + "WW.", +] + +CANE = [ + "...xxxxxx...", + "..xxxxxxxx..", + ".xxx....xxx.", + "xxx......xxx", + "xxx......xxx", + "xx.......xxx", +] + [".........xxx"] * 19 + +FLAMES = [ + [".Y.", "YYY", "YWY", "OWO", ".O."], + ["Y..", ".YY", "YWY", "OWO", ".O."], + ["..Y", "YY.", "YWY", "OWO", ".O."], +] + +MUG = [ + "WmWmWWmW....", + "cccccccc....", + "RRRRRRRR....", + "RRRRRRRRRR..", + "RWRRRRRR.R..", + "RRRRRRRR.R..", + "RRRWRRRR.R..", + "RRRRRRRRRR..", + "RRRRRRRR....", + ".RRRRRR.....", +] + +HOUSE_ROOF = [ + "..........WWWW..........", + "........WWWWWWWW........", + "......WWWWWWWWWWWW......", + "....WWWWWWWWWWWWWWWW....", + "..WWrrrrrrrrrrrrrrrrWW..", + "WWrrrrrrrrrrrrrrrrrrrrWW", +] + +SLEDDER = [ + "..RW....", + "..RR....", + "..SS....", + ".BBBB...", + "tttttttt", + ".t....t.", +] + +ENGINE = [ + ".........kk.", + "..RRRR...kk.", + "..RyyR..kkkk", + ".RRRRRRRRRRR", + "RRRRRRRRRRRR", + "kkkkkkkkkkkk", + ".ww..ww..ww.", +] + +TRAIN_CAR = [ + "..PP.qq.", + "..PP.qq.", + "GGGGGGGG", + "GGGGGGGG", + "kkkkkkkk", + ".ww..ww.", +] + +PALETTE = { + "G": GREEN, + "g": "#C06828", + "T": BROWN, + "t": "#A07040", + "B": "#8A5A30", + "Y": GOLD, + "R": RED, + "W": WHITE, + "S": SKIN, + "k": "#9A6030", + "c": "#3A2010", + "E": "#6A4020", + "l": "#C09070", + "w": "#FFFFFF", + "e": "#303040", + "O": "#FF8020", + "o": "#B08000", + "x": "#FFFFFF", + "m": "#FFFFFF", + "r": "#902818", + "y": "#FFE070", + "P": "#FF40A0", + "q": "#40C0FF", + "n": "#3A2010", +} + +def pal(**overrides): + p = dict(PALETTE) + p.update(overrides) + return p + +def lit(f, offset = 0, step = 4): + """Tree-light palette for frame f: a..d rotate through LIGHTS.""" + return {k: LIGHTS[(f // step + i + offset) % len(LIGHTS)] for i, k in enumerate(["a", "b", "c", "d"])} + +# ------------------------------------------------------------------ scenes +# One function per day count. Each takes the frame index (0..NF-1) and +# returns a 40x32 widget. + +def s_forest(f): # 25: snowy pine forest + trees = [] + for x, y in [(0, 18), (9, 16), (18, 19), (26, 15), (33, 18)]: + trees.append(sprite(TREE_SMALL, pal(G = DARK_GREEN if x % 2 else GREEN), x, y)) + return scene([twinkles(f, 6, 3, 12), ground(25), trees, snow(f, 22, 1)]) + +def s_star_on_tree(f): # 24: star drops onto the tree, then the lights come on + landed = f >= 12 + star_y = -5 + min(f, 12) * 7 // 12 + p = pal(a = "#303030", b = "#303030", c = "#303030", d = "#303030") + if landed: + p.update(lit(f)) + out = [ground(29), sprite(TREE_BIG, p, 12, 12), sprite(STAR_SMALL, pal(Y = "#FFFFFF" if landed and f % 4 < 2 else GOLD), 17, star_y + 5)] + if landed and f < 20: + r = f - 11 + for dx, dy in [(-1, -1), (1, -1), (-1, 1), (1, 1)]: + out.append(px(19 + dx * r, 9 + dy * r // 2, "#FFF080")) + return scene(out) + +def s_presents_stack(f): # 23: presents drop and stack up + boxes = [ + (12, 24, 16, 7, RED, GOLD), + (14, 17, 12, 7, "#2060E0", WHITE), + (16, 11, 8, 6, GREEN, RED), + ] + out = [ground(31, "#3A2A20")] + for i, (x, y, w, h, c, rib) in enumerate(boxes): + t = f - i * 6 + if t < 0: + continue + yy = y if t >= 6 else -h + (y + h) * t // 6 + out.append(rect(x, yy, w, h, c)) + out.append(rect(x + w // 2 - 1, yy, 2, h, rib)) + out.append(rect(x, yy + h // 2, w, 1, rib)) + if f >= 18: + out.append(sprite(["R.R", ".R.", "R.R"], PALETTE, 18, 8)) + out += twinkles(f, 8, 9, 22) + return scene(out) + +def s_train(f): # 22: toy train carrying presents + x = -36 + f * 76 // NF + wheels = pal(w = "#C0C0C0" if f % 2 else "#707070") + out = [rect(0, 29, W, 1, "#7A5A40"), rect(0, 30, W, 2, "#3A2A20")] + for i in range(0, W, 4): + out.append(px((i - f) % W, 30, "#7A5A40")) + out.append(sprite(TRAIN_CAR, wheels, x, 23)) + out.append(sprite(TRAIN_CAR, wheels, x + 9, 23)) + out.append(sprite(ENGINE, wheels, x + 18, 22)) + for k in range(3): + age = (f + k * 4) % 12 + out.append(px(x + 27 - age // 2, 21 - age, "#9098A8" if age < 6 else "#505868")) + return scene([twinkles(f, 6, 5, 14), out]) + +def s_snow_globe(f): # 21: snow globe, shaken at the start of the loop + shake = [2, -2, 2, -2, 1, -1, 0][f] if f < 7 else 0 + cx = 20 + shake + glass = disc(cx, 13, 12, lambda dx, dy: "#203050" if dx * dx + dy * dy > 121 else "#0A1428") + inner = [] + for i in range(18): + a = (i * 37 + f * (6 if f < 7 else 1)) % 360 + r = 2 + rnd(i, 9) + y = 13 + int(r * math.sin(math.radians(a))) + (f // 3 if f >= 7 else 0) + x = cx + int(r * math.cos(math.radians(a))) + if (x - cx) * (x - cx) + (y - 13) * (y - 13) < 110 and y < 22: + inner.append(px(x, y, WHITE)) + return scene([ + glass, + rect(cx - 9, 21, 19, 2, SNOW), + sprite(TREE_SMALL, PALETTE, cx - 3, 14), + inner, + px(cx - 7, 6, "#8090B0"), + px(cx - 8, 7, "#8090B0"), + rect(cx - 11, 25, 23, 2, DARK_BROWN), + rect(cx - 12, 27, 25, 4, BROWN), + rect(cx - 12, 28, 25, 1, GOLD), + ]) + +def s_sledding(f): # 20: sledding down the hill + def hill(x, y): + return SNOW if y >= 6 + x * 22 // 40 else None + + sx = -8 + f * 52 // NF + sy = 6 + (sx + 4) * 22 // 40 - 6 + out = [twinkles(f, 5, 7, 8), raster(0, 0, W, H, hill), sprite(TREE_SMALL, pal(G = DARK_GREEN), 30, 13)] + for k in range(1, 4): + out.append(px(sx - k * 2, sy + 5 - k + (f + k) % 2, WHITE)) + out.append(sprite(SLEDDER, pal(B = "#2F6BFF"), sx, sy)) + return scene(out) + +def s_star(f): # 19: big twinkling star + bright = f % 8 < 4 + out = [] + r = f % 8 + for dx, dy in [(-1, -1), (1, -1), (-1, 1), (1, 1)]: + for k in range(r // 2): + out.append(px(19 + dx * (9 + k), 15 + dy * (9 + k) * 3 // 4, "#806000" if k else "#FFF0A0")) + return scene([ + twinkles(f, 14, 11), + out, + sprite(STAR_BIG, pal(Y = "#FFF080" if bright else GOLD), 12, 8), + px(19, 15, "#FFFFFF") if bright else None, + ]) + +def s_lights(f): # 18: two strands of chasing lights + out = [] + for strand, base in [(0, 4), (1, 18)]: + def sag(x): + return base + (x % 20) * (20 - x % 20) // 25 + + for x in range(W): + out.append(px(x, sag(x), "#205020")) + for i, x in enumerate(range(2 + strand * 2, W, 5)): + c = LIGHTS[(i + f // 3 + strand) % len(LIGHTS)] + on = (i + f // 2) % 3 != 0 + y = sag(x) + 1 + out.append(px(x, y, "#304030")) + out.append(rect(x - 1 if on else x, y + 1, 3 if on else 1, 2, c if on else "#303030")) + return scene(out) + +def s_house(f): # 17: cozy house with chimney smoke + win = "#FFD050" if f % 16 < 13 else "#FFB030" + out = [twinkles(f, 8, 13, 10), ground(27)] + out.append(rect(27, 6, 4, 8, "#904030")) + out.append(rect(26, 5, 6, 1, WHITE)) + for k in range(5): + age = (f + k * 6) % 30 + out.append(px(29 + wave(age, 12, 2), 4 - age // 3, "#8088A0" if age < 12 else "#404858")) + out.append(sprite(HOUSE_ROOF, PALETTE, 8, 8)) + out.append(rect(10, 14, 20, 13, "#B04A28")) + out.append(rect(13, 17, 4, 4, win)) + out.append(rect(23, 17, 4, 4, win)) + out.append(rect(14, 17, 1, 4, "#B04A28")) + out.append(rect(24, 17, 1, 4, "#B04A28")) + out.append(rect(18, 20, 4, 7, DARK_BROWN)) + out.append(sprite(["GGG", "G.G", "GGG"], pal(G = GREEN), 19, 16)) + out.append(snow(f, 14, 21)) + return scene(out) + +def s_snowflake(f): # 16: big rotating snowflake + a0 = math.pi / 3 * f / NF # rotates 60 degrees per loop: seamless + out = [snow(f, 10, 4, 1, "#506080")] + cx, cy = 20, 15 + for k in range(6): + a = a0 + k * math.pi / 3 + for r in range(1, 12): + out.append(px(cx + iround(r * math.cos(a)), cy + iround(r * math.sin(a)), "#C0E0FF" if r < 11 else WHITE)) + for r, l in [(5, 3), (8, 2)]: + for side in [1, -1]: + b = a + side * math.pi / 4 + bx = cx + r * math.cos(a) + by = cy + r * math.sin(a) + for j in range(1, l + 1): + out.append(px(iround(bx + j * math.cos(b)), iround(by + j * math.sin(b)), "#80B8FF")) + out.append(rect(cx - 1, cy - 1, 3, 3, WHITE)) + return scene(out) + +def s_cocoa(f): # 15: hot cocoa with steam + out = [rect(4, 28, 32, 1, "#5A3A20"), sprite(MUG, PALETTE, 13, 18)] + for k in range(3): + for j in range(5): + age = (f + j * 6) % 30 + if age < 2: + continue + y = 17 - age // 2 + x = 15 + k * 3 + wave(age + k * 4, 12, 1) + out.append(px(x, y, "#A0A8B8" if age < 10 else ("#606878" if age < 20 else "#383C48"))) + out.append(sprite(["..G", "GRG", "G.."], PALETTE, 6, 25)) + return scene(out) + +def s_wreath(f): # 14: wreath with twinkling berries and a bow + def ring(dx, dy): + d = dx * dx + dy * dy + if d < 49: + return None + return DARK_GREEN if (dx * 3 + dy * 5) % 4 == 0 else GREEN + + out = [disc(20, 14, 12, ring)] + for i in range(10): + a = i * 2 * math.pi / 10 + x = 20 + iround(9.5 * math.cos(a)) + y = 14 + iround(9.5 * math.sin(a)) + on = (i + f // 3) % 4 != 0 + out.append(px(x, y, LIGHTS[(i + f // 6) % len(LIGHTS)] if on else DARK_RED)) + out.append(sprite([ + "RR...RR", + "RRR.RRR", + "RRRRRRR", + "RRR.RRR", + "RR.R.RR", + "..R.R..", + ".R...R.", + ], pal(R = "#F02828"), 17, 22)) + return scene(out) + +def s_candle(f): # 13: flickering candle + glow_r = 6 + (1 if rnd(f, 3) == 0 else 0) + out = [ + disc(20, 8, glow_r, lambda dx, dy: "#2A1404" if dx * dx + dy * dy > 12 else "#4A2808"), + sprite(FLAMES[rnd(f * 3 + 1, 3)], PALETTE, 19, 5), + rect(20, 10, 1, 1, "#303030"), + ] + for y in range(11, 27): + out.append(rect(17, y, 7, 1, RED if (y + f // 4) % 4 else WHITE)) + out.append(rect(22, 11, 1, 16, "#FF6060")) + out.append(rect(9, 27, 23, 2, DARK_GREEN)) + out.append(sprite([ + "..GG.........GG..", + ".GGGGRR...RRGGGG.", + "GGGG.RR...RR.GGGG", + ], pal(R = "#FF2020"), 12, 26)) + return scene(out) + +def s_present_pop(f): # 12: a present whose lid pops open + t = f % 16 + lid = [0, 0, 0, 0, 2, 5, 7, 8, 8, 7, 5, 2, 0, 0, 0, 0][t] + out = [ground(30, "#3A2A20"), rect(12, 18, 16, 12, "#2060E0"), rect(19, 18, 2, 12, GOLD)] + if lid > 0: + for i in range(lid): + out.append(px(14 + rnd(f * 7 + i, 12), 17 - rnd(f * 5 + i, lid + 4), LIGHTS[(i + f) % len(LIGHTS)])) + out.append(rect(11, 15 - lid, 18, 3, "#3070FF")) + out.append(rect(19, 15 - lid, 2, 3, GOLD)) + out.append(sprite(["YY..YY", ".YYYY."], PALETTE, 17, 13 - lid)) + return scene(out) + +def s_tree(f): # 11: Christmas tree with twinkling lights and gifts + return scene([ + ground(29), + sprite(STAR_SMALL, pal(Y = "#FFFFFF" if f % 8 < 2 else GOLD), 17, 7), + sprite(TREE_BIG, pal(**lit(f, 0, 2)), 12, 11), + rect(6, 24, 6, 5, RED), + rect(8, 24, 2, 5, GOLD), + rect(28, 25, 6, 4, "#2060E0"), + rect(28, 26, 6, 1, WHITE), + snow(f, 8, 30, 1, "#607090"), + ]) + +def s_ornament(f): # 10: swinging ornament + swing = wave(f, NF, 6) + bx = 20 + swing + by = 17 + + def ball(dx, dy): + if dx < -2 and dy < -3 and dx > -6: + return "#FFB0B0" + if dy == 0 or dy == 1: + return GOLD + if dy == 3 and (dx + f // 2) % 3 == 0: + return "#FFFFFF" + return RED + + out = line(20, 0, bx, by - 9, "#808080") + out.append(rect(bx - 1, by - 9, 3, 2, GOLD)) + out.append(disc(bx, by, 7, ball)) + return scene([twinkles(f, 10, 41), out]) + +def s_candy_cane(f): # 9: candy cane with scrolling stripes + def cane(x, y): + if CANE[y][x] != "x": + return None + return RED if ((x + y + f // 2) // 2) % 2 == 0 else WHITE + + return scene([ + twinkles(f, 8, 51), + raster(14, 4, 12, len(CANE), cane), + sprite(["GG.GG", ".GRG.", "..R.."], pal(R = "#FF2020"), 21, 14), + ]) + +def s_bells(f): # 8: jingle bells swinging + tilt = wave(f, 16, 3) + out = [sprite(["RR.RR", ".RRR.", "R...R"], PALETTE, 17, 2)] + for bx, sgn in [(9, 1), (22, -1)]: + t = tilt * sgn + for r in range(len(BELL)): + out.append(sprite([BELL[r]], PALETTE, bx + t * r // 7, 6 + r)) + for k in range(2): + age = (f + k * 16) % NF + if age < 20: + out.append(sprite(NOTE, pal(W = "#FFE070" if age < 10 else "#806820"), 4 + k * 28 + wave(age, 10, 1), 20 - age // 2)) + out.append(rect(0, 26, W, 6, None)) + return scene(out) + +def s_snowman(f): # 7: snowman waving + up = f % 8 < 4 + arm = [(12, 10), (13, 9), (14, 8), (15, 7), (15, 6), (16, 7)] if up else [(12, 10), (13, 10), (14, 9), (15, 9), (16, 8), (16, 10)] + out = [ground(29), sprite(SNOWMAN, pal(k = "#404858", W = WHITE, e = "#202028"), 13, 8)] + out += [px(x + 13, y + 8, "#8A5A30") for x, y in arm] + out += [px(13 + x, 8 + y, "#8A5A30") for x, y in [(0, 10), (-1, 11), (-2, 12), (-3, 12), (-3, 13)]] + out.append(snow(f, 16, 61)) + return scene(out) + +def s_gingerbread(f): # 6: jumping gingerbread man + t = f % 16 + hop = [0, 0, 3, 5, 7, 8, 8, 7, 5, 3, 0, 0, 0, 0, 0, 0][t] + out = [rect(6, 28, 28, 2, "#C0C0D0")] + if hop == 0 and (t == 10 or t == 11): + out.append(px(12, 27, "#C06828")) + out.append(px(27, 27, "#C06828")) + out.append(sprite(GINGER, PALETTE, 14, 14 - hop)) + return scene([twinkles(f, 8, 71, 20), out]) + +def s_reindeer(f): # 5: reindeer with a glowing red nose + on = f % 8 < 5 + out = [] + if on: + out.append(disc(20, 29, 4, lambda dx, dy: "#401010" if dx * dx + dy * dy > 6 else "#701818")) + out.append(sprite(REINDEER_HEAD, PALETTE, 12, 13)) + out.append(rect(19, 28, 3, 2, "#FF2020" if on else "#801010")) + out.append(px(19, 28, "#FFA0A0") if on else None) + return scene([twinkles(f, 10, 81, 12), out]) + +def s_fireplace(f): # 4: crackling fireplace + def brick(x, y): + if y % 4 == 3 or (x + (y // 4) * 3) % 6 == 0: + return "#4A2018" + return "#903828" + + out = [raster(4, 6, 32, 26, brick), rect(2, 4, 36, 3, "#5A3A20"), rect(11, 13, 18, 19, "#100604")] + for x in range(12, 28): + h = 3 + rnd(f * 41 + x * 7, 7) - abs(x - 20) // 3 + for y in range(h): + c = "#FFE060" if y < h // 3 else ("#FF9020" if y < 2 * h // 3 else "#D02010") + out.append(px(x, 28 - y, c)) + out.append(rect(13, 29, 14, 2, BROWN)) + out.append(rect(15, 28, 10, 1, DARK_BROWN)) + out.append(sprite(STOCKING, PALETTE, 7, 7)) + out.append(sprite(STOCKING, pal(R = "#20A040", G = RED), 25, 7)) + return scene(out) + +def s_stockings(f): # 3: stockings with goodies bobbing + out = [rect(0, 10, W, 2, "#7A4A20"), rect(0, 12, W, 1, "#4A2A10")] + for i, (x, col) in enumerate([(5, RED), (24, "#2F6BFF")]): + bob = [0, 1, 2, 3, 3, 2, 1, 0][(f // 2 + i * 4) % 8] + sw = wave(f + i * 8, NF, 1) + if i == 0: + out.append(sprite(["xxx", "x.x", "..x", "..x", "..x"], pal(x = RED if (f // 4) % 2 else WHITE), x + 2 + sw, 9 - bob)) + else: + out.append(rect(x + 2 + sw, 10 - bob, 4, 4, GREEN)) + out.append(rect(x + 3 + sw, 10 - bob, 1, 4, GOLD)) + out.append(sprite(STOCKING, pal(R = col), x + sw, 13)) + return scene([twinkles(f, 6, 91, 8), out]) + +def s_cookies(f): # 2: cookies and milk for Santa (disappearing) + out = [rect(1, 27, 24, 2, "#D0D8E8"), rect(3, 29, 20, 1, "#8090A0")] + for i in range(3): + gone = 8 + i * 8 + if f < gone - 3: + out.append(sprite(COOKIE, PALETTE, 3 + i * 7, 22)) + elif f < gone: + out.append(sprite(COOKIE_BITTEN, PALETTE, 3 + i * 7, 22)) + else: + out.append(px(5 + i * 7, 26, "#9A6030")) + level = 13 - f * 10 // NF + out.append(rect(28, 13, 1, 15, "#8090B0")) + out.append(rect(36, 13, 1, 15, "#8090B0")) + out.append(rect(28, 28, 9, 1, "#8090B0")) + out.append(rect(29, 28 - level, 7, level, WHITE)) + return scene([twinkles(f, 8, 101, 12), out]) + +def s_eve(f): # 1: Santa's sleigh across the moon + x = -32 + f * 76 // NF + y = 11 + wave(f, NF, 2) + out = [twinkles(f, 14, 111), disc(26, 12, 9, lambda dx, dy: "#E8E0B0" if (dx - 3) * (dx - 3) + (dy + 2) * (dy + 2) > 3 else "#C8C098")] + out.append(sprite(SLEIGH, PALETTE, x, y)) + out += line(x + 11, y + 4, x + 14, y + 2, "#A08060") + for k in range(2): + out.append(sprite(REINDEER, pal(n = "#FF2020" if k == 1 and f % 4 < 2 else "#3A2010"), x + 14 + k * 10, y - 1 + (f + k) % 2)) + for k in range(1, 6): + out.append(px(x - k * 2, y + 6 - k % 2, "#FFE070" if k < 3 else "#806820")) + return scene(out) + +# ------------------------------------------- days 26-45 (sprites + scenes) + +def rotated(rows, p, x, y, ang, pvx, pvy): + """Sprite rotated by ang degrees (clockwise on screen; 0 = as drawn) about its pixel (pvx, pvy), + which is drawn at scene position (x, y).""" + w = max([len(r) for r in rows]) + h = len(rows) + rr = 1 + int(math.sqrt(max(pvx, w - pvx) * max(pvx, w - pvx) + max(pvy, h - pvy) * max(pvy, h - pvy))) + c = math.cos(math.radians(ang)) + s = math.sin(math.radians(ang)) + + def fn(xx, yy): + dx = xx - rr + dy = yy - rr + sx = iround(c * dx + s * dy) + pvx + sy = iround(-s * dx + c * dy) + pvy + if sy < 0 or sy >= h or sx < 0 or sx >= len(rows[sy]): + return None + return p.get(rows[sy][sx]) + + return raster(x - rr, y - rr, 2 * rr + 1, 2 * rr + 1, fn) + +def text_at(x, y, s, c, font = "tom-thumb"): + return render.Padding(pad = (x, y, 0, 0), child = render.Text(s, font = font, color = c)) + +ELF_HAT = [ + "...............GG...", + ".............GGGG...", + "...........GGGGG....", + ".........GGGGGG.....", + "........GGGGGG......", + ".......GGGGGGG......", + "......GGGGRGGG......", + ".....GGGGGGGGG......", + "....GGGGGGGGGG......", + "....GGGRGGGGGGG.....", + "...GGGGGGGGGGGG.....", + "...GGGGGGGGGRGGG....", + "..WWWWWWWWWWWWWWWW..", + "..WWWWWWWWWWWWWWWW..", +] + +BELL_SMALL = [ + "..Y..", + ".YYY.", + ".YYY.", + "YYYYY", + "..o..", +] + +SOLDIER = [ + "..kkk..", + "..kkk..", + "..kkk..", + "..kYk..", + "..SSS..", + "..SeS..", + "..SSS..", + ".RRRRR.", + "SRYRYRS", + "SRRRRRS", + ".RYRYR.", + ".RRRRR.", + ".WWWWW.", + ".BB.BB.", +] + +PENGUIN = [ + "...RRW.", + "..RRR..", + "..kkk..", + ".kkkkk.", + ".kwkwk.", + ".kwOwk.", + "kkwwwkk", + "kkwwwkk", + "kkwwwkk", + ".kwwwk.", + ".OO.OO.", +] + +HEART = [ + ".R.R.", + "RRRRR", + ".RRR.", + "..R..", +] + +ANGEL = [ + "...yyy...", + "...SSS...", + "...SeS...", + "...SSS...", + "..WWWWW..", + "..WWYWW..", + ".WWWWWWW.", + ".WWWWWWW.", + "WWWWWWWWW", + "WWWWWWWWW", +] + +WING_UP = ["YW..", "WWW.", ".WWW", "..WW"] +WING_DOWN = ["..WW", ".WWW", "WWW.", "W..."] + +ENVELOPE = [ + "WWWWWWW", + "WRWWWRW", + "WWRWRWW", + "WWWRWWW", + "WWWWWWW", +] + +SKATER = [ + ".RR.", + ".SS.", + "GGGR", + "GGG.", + ".BB.", + ".B.B", + "ww.w", +] + +CARDINAL = [ + "...R....", + "..RRR...", + ".kkRR...", + "OkRRRR..", + "..RRRRRR", + "...RRRRR", + "....RR..", + "....oo..", +] + +TEDDY = [ + ".BB.......BB.", + "BlBBBBBBBBBlB", + "BBBBBBBBBBBBB", + ".BBeBBBBBeBB.", + ".BBBBlllBBBB.", + ".BBBlleBlBBB.", + "..BBBlllBBB..", + "....RRYRR....", + "...BBBBBBB...", + "..BBBlllBBB..", + "..BBlllllBB..", + "..BBlllllBB..", + "..BBBlllBBB..", + ".BBBB...BBBB.", + ".lllB...Blll.", +] + +TEDDY_ARM = ["BBB", "BBB", "BBB", "BBB", "BBB", ".l."] + +HORSE = [ + "............MHH...", + "...........MHHHH..", + "..........MHHeHHH.", + "..........MHHHHHHH", + "..........HHHH....", + "..T......HHHH.....", + "..TTHHsssHHHH.....", + "...THHsssHHHH.....", + "....HHHHHHHHH.....", + "....H.H....H.H....", + "....H.H....H.H....", + "....H.H....H.H....", + "R...H.H....H.H...R", + ".RR.H.H....H.H.RR.", + "...RRRRRRRRRRRR...", +] + +TOP = [ + ".....hh.....", + ".....hh.....", + "..xxxxxxxx..", + ".xxxxxxxxxx.", + "xxxxxxxxxxxx", + "xxxxxxxxxxxx", + ".xxxxxxxxxx.", + "..xxxxxxxx..", + "....xxxx....", + ".....xx.....", +] + +CRACKER_L = [ + "Y...RRRRR", + "YY.RRRRRR", + "YYYRRWRRR", + "YY.RRRRRR", + "Y...RRRRR", +] + +CRACKER_R = [r[::-1] for r in CRACKER_L] + +CROWN = ["Y.Y.Y", "YYYYY", "YRYqY"] + +MITTEN = [ + "WWWWW..", + "WWWWW..", + "RRRRR..", + "RRRRRR.", + "RRWRRRR", + "RRRRR.R", + "RRWRR..", + "RRRRR..", + ".RRR...", +] + +def s_elf_hat(f): # 26: elf hat with a jingling bell on the tip + t = f % 16 + hop = [0, 1, 2, 2, 1, 0, 0, 0, 0, 1, 2, 2, 1, 0, 0, 0][t] + sw = wave(f, 16, 4) + tx, ty = 24, 12 - hop + out = [ground(28), sprite(ELF_HAT, pal(G = "#20B040", R = "#FF3030"), 8, 14 - hop)] + out += line(tx, ty + 2, tx + 3 + sw, ty + 8, "#A0A0A0") + out.append(sprite(BELL_SMALL, PALETTE, tx + 1 + sw, ty + 8)) + if abs(sw) >= 3: + side = 1 if sw > 0 else -1 + for k in range(3): + out.append(px(tx + 3 + sw + side * (4 + k), ty + 7 + k * 2 - 2, "#FFF080")) + return scene([twinkles(f, 8, 121, 12), out]) + +def s_toy_soldier(f): # 27: toy soldier marching + x = -8 + f * 50 // NF + step = (f // 2) % 2 + out = [rect(0, 29, W, 3, "#3A2A20")] + out.append(sprite(SOLDIER, pal(k = "#404070", B = "#202050", e = "#202028"), x, 12 + step)) + legs = [".B...B.", ".B...B.", "kk...kk"] if step else ["..B.B..", "..B.B..", "..kk.kk"] + out.append(sprite(legs, pal(B = "#3040A0", k = "#606060"), x, 26)) + return scene([twinkles(f, 8, 131, 12), out]) + +def s_penguin(f): # 28: penguin in a Santa hat waddling over the ice + x = -7 + f * 52 // NF + tilt = 12 if (f // 2) % 2 else -12 + out = [rect(0, 26, W, 6, "#90C8F0")] + for k in range(3): + sx = (k * 14 + 30 - f) % W + out.append(rect(sx, 28 + k % 2 * 2, 4, 1, WHITE)) + out.append(rotated(PENGUIN, pal(k = "#30508A", w = WHITE), x + 3, 25, tilt, 3, 10)) + return scene([twinkles(f, 10, 141, 18), out]) + +def s_mistletoe(f): # 29: mistletoe with hearts floating up + out = line(20, 0, 20, 7, "#A08060") + out.append(sprite([ + ".GG.....GG.", + "GGGG...GGGG", + ".GGGGWGGGG.", + "...GWGWG...", + "..GGGWGGG..", + ".GGG.W.GGG.", + "GGG.....GGG", + ], pal(W = "#FFFFFF"), 15, 7)) + out.append(sprite(["RR.RR", ".RRR.", "R.R.R"], PALETTE, 18, 5)) + for k in range(3): + age = (f + k * 11) % NF + c = "#FF60A0" if age < 16 else ("#A03060" if age < 24 else "#501830") + out.append(sprite(HEART, pal(R = c), 6 + k * 11 + wave(age + k * 5, 12, 1), 30 - age)) + return scene(out) + +def s_angel(f): # 30: angel with flapping wings + bob = wave(f, 16, 1) + flap = (f // 3) % 2 + y = 9 + bob + glow = "#FFF080" if f % 8 < 4 else GOLD + wing = WING_UP if flap else WING_DOWN + out = [ + rect(16, y - 3, 7, 1, glow), + px(15, y - 2, glow), + px(23, y - 2, glow), + sprite([r[::-1] for r in wing], pal(W = "#E0E8FF", Y = "#E0E8FF"), 12, y + 4), + sprite(wing, pal(W = "#E0E8FF", Y = "#E0E8FF"), 24, y + 4), + sprite(ANGEL, pal(y = GOLD, e = "#202028"), 15, y - 1), + ] + return scene([twinkles(f, 14, 151), out]) + +def s_mailbox(f): # 31: letter to Santa flying into the mailbox + out = [ground(29), rect(27, 16, 2, 13, BROWN)] + out.append(rect(21, 9, 14, 8, "#3060C0")) + out.append(rect(21, 9, 1, 8, "#204090")) + out.append(rect(22, 11, 4, 1, "#101830")) + up = f >= 18 + if up: + out.append(rect(35, 4, 1, 8, "#A0A0A0")) + out.append(rect(36, 4, 3, 2, "#FF2020")) + else: + out.append(rect(35, 11, 4, 1, "#A0A0A0")) + out.append(rect(38, 11, 2, 2, "#FF2020")) + if f < 16: + ex = -7 + f * 29 // 16 + ey = 14 - (f * (16 - f)) // 6 + out.append(sprite(ENVELOPE, PALETTE, ex, ey)) + if up and f < 26: + out.append(sprite(HEART, pal(R = "#FF60A0"), 25, 4 - (f - 18) // 2)) + return scene([twinkles(f, 6, 161, 8), out]) + +def s_skater(f): # 32: ice skater gliding round a pond + out = [disc(20, 24, 7, lambda dx, dy: "#80B8E8" if (dx + dy) % 7 else "#C0E0FF")] + out.append(rect(0, 28, W, 4, SNOW)) + out.append(raster(2, 19, 36, 10, lambda x, y: "#80B8E8" if ((x - 18) * (x - 18)) * 9 + ((y - 5) * (y - 5)) * 64 <= 18 * 18 * 9 else None)) + for k in range(5, 0, -1): + a = 2 * math.pi * (f - k * 2) / NF + out.append(px(20 + iround(15 * math.cos(a)), 24 + iround(3 * math.sin(a)), "#FFFFFF" if k < 3 else "#C0E0FF")) + a = 2 * math.pi * f / NF + sx = 20 + iround(15 * math.cos(a)) + sy = 24 + iround(3 * math.sin(a)) + sk = SKATER if math.sin(a) > 0 else [r[::-1] for r in SKATER] + out.append(sprite(sk, pal(G = "#30C060", B = "#304070", w = "#C0C0C0"), sx - 2, sy - 7)) + out.append(sprite(TREE_SMALL, PALETTE, 2, 10)) + out.append(sprite(TREE_SMALL, pal(G = DARK_GREEN), 31, 11)) + return scene([twinkles(f, 8, 171, 10), out]) + +def s_snowballs(f): # 33: snowball fight between two forts + out = [ground(27)] + out.append(disc(5, 27, 6, lambda dx, dy: WHITE if dy <= 0 else None)) + out.append(disc(34, 27, 6, lambda dx, dy: WHITE if dy <= 0 else None)) + out.append(sprite(["RR", "SS"], PALETTE, 4, 19 + (1 if f % 16 > 8 else 0))) + out.append(sprite(["GG", "SS"], pal(G = "#30C060"), 34, 19 + (1 if f % 16 <= 8 else 0))) + t = f % 16 + left = (f // 16) % 2 == 0 + if t < 12: + x = 9 + t * 22 // 12 + if not left: + x = 39 - x + y = 20 - (t * (12 - t)) // 3 + out.append(rect(x, y, 2, 2, WHITE)) + else: + hx = 33 if left else 6 + for dx, dy in [(-2, -1), (2, -1), (-1, -2), (1, -2), (0, -3)]: + out.append(px(hx + dx * (t - 11), 20 + dy * (t - 11) // 2, WHITE)) + return scene([twinkles(f, 8, 181, 12), out]) + +def s_cardinal(f): # 34: cardinal hopping along a snowy branch + out = line(0, 24, 39, 14, BROWN) + out += line(0, 25, 39, 15, DARK_BROWN) + out += line(0, 23, 39, 13, SNOW) + out += line(26, 18, 33, 11, BROWN) + t = f % 16 + hop = [0, 0, 0, 0, 2, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0][t] + pos = 6 + (f // 16) * 10 + (min(t, 8) - 4 if t >= 4 else 0) * 10 // 4 // 2 + bx = pos + by = 24 - (bx + 4) * 10 // 39 - 8 - hop + out.append(sprite(CARDINAL, pal(R = "#FF2020", k = "#300808", o = "#806020"), bx, by)) + if t in [8, 9, 10]: + for k in range(3): + out.append(px(bx + 2 + k * 2, by + 10 + (t - 8) + k % 2, WHITE)) + out.append(snow(f, 10, 191)) + return scene(out) + +def s_aurora(f): # 35: northern lights over the pines + def sky(x, y): + top = 3 + iround(3 * math.sin((x + f * 1.25) / 5.0) + 2 * math.sin((x * 2 - f * 2.5) / 9.0)) + d = y - top + if d < 0 or d > 12: + return None + if d < 2: + return "#60FFB0" + if d < 5: + return "#20C080" + if d < 8: + return "#108060" if (x + y + f) % 3 else "#6040A0" + return "#083828" + + out = [twinkles(f, 10, 201), raster(0, 0, W, 22, sky)] + for x, y in [(0, 21), (6, 19), (13, 22), (20, 18), (27, 21), (33, 20)]: + out.append(sprite(TREE_SMALL, pal(G = "#0A3018", T = "#2A1A08"), x, y)) + out.append(ground(28, "#607090")) + return scene(out) + +def s_teddy(f): # 36: teddy bear waving + ang = -125 - wave(f, 12, 25) + p = pal(B = "#B07038", l = "#E0B080", e = "#202028", R = "#E02020") + return scene([ + twinkles(f, 8, 211, 12), + ground(30, "#3A2A20"), + rotated(TEDDY_ARM, p, 14, 18, 35, 1, 0), + rotated(TEDDY_ARM, p, 24, 18, ang, 1, 0), + sprite(TEDDY, p, 13, 9), + ]) + +def s_drum(f): # 37: toy drum with sticks beating + def drum(x, y): + if y < 3: + return "#F0F0F0" if y > 0 or (x > 1 and x < 18) else None + if y == 3 or y == 12: + return GOLD + zig = (x % 6) if (x % 6) < 3 else 6 - x % 6 + return WHITE if y - 5 == zig or y - 5 == zig + 1 else RED + + hit_l = f % 4 < 2 + out = [raster(10, 15, 20, 13, drum)] + if hit_l: + out += line(4, 8, 13, 15, "#D0A060") + out += line(36, 4, 29, 9, "#D0A060") + else: + out += line(4, 4, 11, 9, "#D0A060") + out += line(36, 8, 26, 15, "#D0A060") + hx = 13 if hit_l else 26 + for dx, dy in [(-2, -2), (0, -3), (2, -2)]: + out.append(px(hx + dx, 13 + dy, "#FFF080")) + out.append(rect(5, 28, 30, 1, "#3A2A20")) + return scene([twinkles(f, 6, 221, 8), out]) + +def s_list(f): # 38: Santa's list getting checked off + out = [rect(7, 2, 26, 26, "#E8D8B0"), rect(6, 27, 28, 3, "#B8A070"), rect(6, 1, 28, 2, "#B8A070")] + out.append(text_at(9, 4, "NICE", "#D02020")) + out.append(text_at(26, 4, "*", "#20A040")) + for i in range(4): + y = 12 + i * 4 + out.append(rect(14, y, 15 - (i * 3) % 5, 1, "#807060")) + done = f >= 6 + i * 6 + if done: + out.append(sprite(["...G", "G.G.", ".G.."], pal(G = "#109030"), 9, y - 1)) + else: + out.append(rect(9, y - 1, 3, 3, "#B0A080")) + out.append(rect(10, y, 1, 1, "#E8D8B0")) + i = min(f // 6, 3) + py = 12 + i * 4 - 6 + (f % 6 // 3) + out += line(13, py + 6, 18, py, "#FFFFFF") + out.append(px(13, py + 6, "#303030")) + return scene(out) + +def s_rocking_horse(f): # 39: rocking horse + ang = wave(f, 16, 12) + p = pal(H = "#D8A060", M = "#FFFFFF", e = "#202028", s = "#E02020", T = "#FFFFFF", R = "#8A4A20") + return scene([twinkles(f, 8, 231, 10), rect(0, 30, W, 2, "#3A2A20"), rotated(HORSE, p, 20, 29, ang, 9, 14)]) + +def s_top(f): # 40: spinning top + wob = wave(f, 16, 2) + + def top(x, y): + ch = TOP[y][x] + if ch == "h": + return "#A0A0A0" + if ch != "x": + return None + return [RED, GOLD, "#2F6BFF", "#30C060"][((x - f) // 2) % 4] + + out = [rect(4, 28, 32, 1, "#3A2A20"), raster(14 + wob, 17, 12, 10, top)] + for k in range(3): + y = 20 + k * 2 + out.append(rect(6 + wob - (f + k) % 3, y, 3, 1, "#506080")) + out.append(rect(31 + wob + (f + k) % 3, y, 3, 1, "#506080")) + out.append(disc(20, 30, 2, lambda dx, dy: "#202838" if dy <= 0 else None)) + return scene([twinkles(f, 8, 241, 14), out]) + +def s_cracker(f): # 41: Christmas cracker pulled with a bang + out = [] + if f < 10: + sh = (f % 2) * 2 - 1 if f > 4 else 0 + out.append(sprite(CRACKER_L, PALETTE, 11 + sh, 13)) + out.append(sprite(CRACKER_R, PALETTE, 20 + sh, 13)) + else: + gap = min(f - 10, 6) + out.append(sprite(CRACKER_L, PALETTE, 11 - gap, 13 + gap // 2)) + out.append(sprite(CRACKER_R, PALETTE, 20 + gap, 13 + gap // 2)) + if f < 13: + out.append(disc(20, 15, 2 + (f - 10) * 2, lambda dx, dy: "#FFF8C0")) + for i in range(14): + age = f - 10 + a = rnd(i, 360) + r = min(age, 8) + rnd(i * 3, 4) + out.append(px(20 + iround(r * math.cos(math.radians(a))), 15 + iround(r * math.sin(math.radians(a)) * 0.6) + max(0, age - 8) // 2, LIGHTS[i % len(LIGHTS)])) + if f >= 14: + out.append(sprite(CROWN, pal(q = "#40C0FF"), 18, 13 - min(f - 14, 8))) + return scene([twinkles(f, 6, 251, 10), out]) + +def s_comet(f): # 42: shooting stars + out = [twinkles(f, 16, 261, 26)] + for k in range(2): + t = (f + k * 16) % NF + if t < 12: + hx = 36 - k * 12 - t * 2 + hy = 2 + k * 4 + t + for j in range(6): + out.append(px(hx + j * 2, hy - j, ["#FFFFFF", "#FFF0A0", "#C0B060", "#807040", "#504028", "#302010"][j])) + out.append(disc(10, 40, 14, lambda dx, dy: "#203040")) + out.append(disc(34, 42, 15, lambda dx, dy: "#18283A")) + out.append(sprite(["..r..", ".rrr.", "rrrrr", "rwrwr", "rrrrr"], pal(w = "#FFD050" if f % 16 < 14 else "#C09030", r = "#6A3020"), 29, 24)) + return scene(out) + +def s_lollipop(f): # 43: spinning swirl lollipop + rot = 2 * math.pi * f / NF + + def swirl(dx, dy): + if dx == 0 and dy == 0: + return WHITE + a = math.atan2(dy, dx) + rot + math.sqrt(dx * dx + dy * dy) * 0.55 + k = int(math.floor(a / (math.pi / 3))) % 3 + return [RED, WHITE, "#30C060"][k] + + return scene([ + twinkles(f, 8, 271), + rect(19, 21, 2, 11, "#E0E0E0"), + disc(20, 12, 9, swirl), + sprite(["RR.RR", ".RRR.", "R...R"], PALETTE, 18, 21), + ]) + +def s_lantern(f): # 44: lamp post glowing in the snow + glow = 9 + (1 if f % 12 < 6 else 0) + gx, gy = 20, 8 + + def halo(dx, dy): + d = dx * dx + dy * dy + return "#3A2808" if d > 36 else "#5A4010" + + out = [disc(gx, gy, glow, halo), ground(29), rect(19, 12, 2, 17, "#303848"), rect(17, 28, 6, 2, "#303848")] + out.append(rect(16, 3, 8, 1, "#303848")) + out.append(rect(17, 4, 6, 7, "#FFD060")) + out.append(rect(19, 4, 2, 7, "#FFF0A0")) + out.append(rect(16, 11, 8, 1, "#303848")) + out.append(sprite(["R.R", ".R."], PALETTE, 19, 13)) + for i in range(20): + x = rnd(281 + i * 7, W) + y = (rnd(281 + i * 13, H) + f) % H + d = (x - gx) * (x - gx) + (y - gy) * (y - gy) + out.append(px(x, y, "#FFF0C0" if d < 100 else "#506080")) + return scene(out) + +def s_mittens(f): # 45: mittens swinging on a clothesline + def sag(x): + return 5 + x * (W - x) // 160 + + out = [twinkles(f, 8, 291, 4)] + for x in range(W): + out.append(px(x, sag(x), "#A09080")) + for i, (x, col) in enumerate([(9, RED), (26, "#30A050")]): + ang = wave(f + i * 5, 16, 18) + out.append(rotated(MITTEN, pal(R = col), x + 2, sag(x) + 2, ang, 2, 0)) + out.append(rect(x + 1, sag(x) - 1, 2, 3, "#B08050")) + out.append(snow(f, 10, 297, 1, WHITE)) + out.append(ground(29)) + return scene(out) + +SCENES = [ + None, # 0: Christmas Day, drawn full-screen + s_eve, + s_cookies, + s_stockings, + s_fireplace, + s_reindeer, + s_gingerbread, + s_snowman, + s_bells, + s_candy_cane, + s_ornament, + s_tree, + s_present_pop, + s_candle, + s_wreath, + s_cocoa, + s_snowflake, + s_house, + s_lights, + s_star, + s_sledding, + s_snow_globe, + s_train, + s_presents_stack, + s_star_on_tree, + s_forest, + s_elf_hat, + s_toy_soldier, + s_penguin, + s_mistletoe, + s_angel, + s_mailbox, + s_skater, + s_snowballs, + s_cardinal, + s_aurora, + s_teddy, + s_drum, + s_list, + s_rocking_horse, + s_top, + s_cracker, + s_comet, + s_lollipop, + s_lantern, + s_mittens, +] + +def scene_for(days): + """Scene for a day count. Past the last scene (45) they repeat from 1.""" + n = len(SCENES) - 1 + if days <= n: + return SCENES[days] + return SCENES[(days - 1) % n + 1] + +# ------------------------------------------------------------------ layout + +def number_panel(days, num_color, label_color): + s = str(days) + font = "10x20" if len(s) <= 2 else "6x13" + return render.Box( + width = PANEL_W, + height = HEIGHT, + child = render.Column( + main_align = "center", + cross_align = "center", + children = [ + render.Text(s, font = font, color = num_color), + render.Text("DAY" if days == 1 else "DAYS", font = "tom-thumb", color = label_color), + ], + ), + ) + +def christmas_frame(f): + """Full-screen card for Christmas Day: chasing light border, snow, text.""" + border = [] + i = 0 + for x in range(1, WIDTH, 4): + for y in [0, HEIGHT - 1]: + border.append(render.Padding(pad = (x, y, 0, 0), child = render.Box(width = 2, height = 1, color = LIGHTS[(i + f // 2) % len(LIGHTS)]))) + i += 1 + for y in range(3, HEIGHT - 2, 4): + for x in [0, WIDTH - 1]: + border.append(render.Padding(pad = (x, y, 0, 0), child = render.Box(width = 1, height = 2, color = LIGHTS[(i + f // 2) % len(LIGHTS)]))) + i += 1 + flakes = [] + for k in range(18): + flakes.append(render.Padding(pad = (2 + rnd(k * 7 + 3, WIDTH - 4), 1 + (rnd(k * 13, 30) + f) % 30, 0, 0), child = render.Box(width = 1, height = 1, color = "#5060A0"))) + merry = render.Row(children = [render.Text(ch, font = "6x13", color = [RED, "#30D050"][(j + f // 4) % 2]) for j, ch in enumerate("MERRY".elems())]) + return render.Stack(children = [ + render.Box(width = WIDTH, height = HEIGHT), + ] + flakes + border + [ + render.Box(width = WIDTH, height = HEIGHT, child = render.Column( + main_align = "center", + cross_align = "center", + children = [merry, render.Text("CHRISTMAS", font = "tb-8", color = "#30D050" if f % 8 < 4 else WHITE)], + )), + ]) + +def build_frames(days, num_color = RED, label_color = "#30D050"): + if days == 0: + return [christmas_frame(f) for f in range(NF)] + draw = scene_for(days) + panel = number_panel(days, num_color, label_color) + return [render.Row(children = [panel, draw(f)]) for f in range(NF)] + +# -------------------------------------------------------------------- main + +def days_until_christmas(): + now = time.now() + tz = time.tz() + today = time.time(year = now.year, month = now.month, day = now.day, location = tz) + year = now.year + if now.month == 12 and now.day > 25: + year += 1 + xmas = time.time(year = year, month = 12, day = 25, location = tz) + return int((xmas - today).hours / 24 + 0.5) # round: DST days are 23/25 h + +def main(config): + override = config.str("days", "").strip() + if override.isdigit(): + days = min(int(override), len(SCENES) - 1) + else: + days = days_until_christmas() + show_from = int(config.str("show_from", "45")) + if days > show_from: + return [] # out of season: skip this card + + return render.Root( + delay = FRAME_MS, + child = render.Animation(children = build_frames( + days, + config.str("number_color", RED), + config.str("label_color", "#30D050"), + )), + ) + +def get_schema(): + return schema.Schema( + version = "1", + fields = [ + schema.Dropdown( + id = "show_from", + name = "Show from", + desc = "Only show the card this many days before Christmas", + icon = "calendar", + default = "45", + options = [ + schema.Option(display = "24 days (Dec 1)", value = "24"), + schema.Option(display = "31 days (late Nov)", value = "31"), + schema.Option(display = "45 days (Nov 10)", value = "45"), + schema.Option(display = "100 days", value = "100"), + schema.Option(display = "All year", value = "366"), + ], + ), + schema.Color(id = "number_color", name = "Number color", desc = "Color of the day count", icon = "palette", default = RED), + schema.Color(id = "label_color", name = "Label color", desc = "Color of DAYS", icon = "palette", default = "#30D050"), + schema.Text(id = "days", name = "Preview day", desc = "Force a day count (0-45) to preview its animation; leave blank", icon = "eye", default = ""), + ], + ) diff --git a/apps/xmasscenes/xmasscenes.webp b/apps/xmasscenes/xmasscenes.webp new file mode 100644 index 0000000000000000000000000000000000000000..0e81708c9c53081501a514c0ca0770f866b63d63 GIT binary patch literal 4158 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 S%70w(9VV^FjBX+xMEoD9aNgqp literal 0 HcmV?d00001 From 36dda7c3767176461aeed00b3f9b1713e5df65c9 Mon Sep 17 00:00:00 2001 From: explorer9957 <364212876+explorer9957@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:47:42 -0500 Subject: [PATCH 2/2] Xmas Scenes: past 45 days, cycle plain winter scenes instead of repeating Christmas Eve ones Co-Authored-By: Claude Opus 5.5 --- apps/xmasscenes/xmasscenes.star | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/apps/xmasscenes/xmasscenes.star b/apps/xmasscenes/xmasscenes.star index fc522e25a..0eac99fc8 100644 --- a/apps/xmasscenes/xmasscenes.star +++ b/apps/xmasscenes/xmasscenes.star @@ -1403,12 +1403,30 @@ SCENES = [ s_mittens, ] +# Plain winter scenes for counts past the last unique day (only reached with +# "Show from" 100 or All year). Christmas-specific scenes (Santa, presents, +# the tree, stockings, ...) stay on their own days. +WINTER = [ + s_mittens, + s_lantern, + s_comet, + s_aurora, + s_cardinal, + s_snowballs, + s_skater, + s_forest, + s_sledding, + s_snowflake, + s_cocoa, + s_snowman, +] + def scene_for(days): - """Scene for a day count. Past the last scene (45) they repeat from 1.""" + """Scene for a day count. Past the last unique scene, cycle through WINTER.""" n = len(SCENES) - 1 if days <= n: return SCENES[days] - return SCENES[(days - 1) % n + 1] + return WINTER[(days - n) % len(WINTER)] # ------------------------------------------------------------------ layout @@ -1476,7 +1494,7 @@ def days_until_christmas(): def main(config): override = config.str("days", "").strip() if override.isdigit(): - days = min(int(override), len(SCENES) - 1) + days = min(int(override), 366) else: days = days_until_christmas() show_from = int(config.str("show_from", "45")) @@ -1512,6 +1530,6 @@ def get_schema(): ), schema.Color(id = "number_color", name = "Number color", desc = "Color of the day count", icon = "palette", default = RED), schema.Color(id = "label_color", name = "Label color", desc = "Color of DAYS", icon = "palette", default = "#30D050"), - schema.Text(id = "days", name = "Preview day", desc = "Force a day count (0-45) to preview its animation; leave blank", icon = "eye", default = ""), + schema.Text(id = "days", name = "Preview day", desc = "Force a day count (0-366) to preview its animation; leave blank", icon = "eye", default = ""), ], )