aboutsummaryrefslogtreecommitdiff
path: root/src/patterns/candycane.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/patterns/candycane.c')
-rw-r--r--src/patterns/candycane.c53
1 files changed, 44 insertions, 9 deletions
diff --git a/src/patterns/candycane.c b/src/patterns/candycane.c
index dbf80de..42a9ad7 100644
--- a/src/patterns/candycane.c
+++ b/src/patterns/candycane.c
@@ -1,23 +1,49 @@
#include "byte_math.h"
#include "pattern.h"
-static rgb_t get_rgb(uint32_t time, size_t x)
+static rgb_t white(uint32_t time, size_t x)
+{
+ int w = calc_w((time & 0xff) + x * 4);
+ rgb_t color;
+ color.color = 0x00ffffff;
+ color.a = 255 - w;
+ return color;
+}
+
+static rgb_t candycane_bg(uint32_t time, size_t x)
{
int r = 0, g = 0, b = 0;
uint8_t time8 = time & 0xff;
- int w = calc_w(time8 + x * 4);
r = 0xff;
g = byte_scale(byte_sin(time8 + x * 2), 0x90);
b = byte_scale(byte_sin(time8 + x * 2), 0x20);
- rgb_t color;
- color.color = 0;
- color.r = clip(r + w);
- color.g = clip(byte_scale(g, AS_BYTE(0.75)) + w);
- color.b = clip(byte_scale(b, AS_BYTE(0.75)) + w);
- return color;
+ rgb_t bg;
+ bg.color = 0;
+ bg.r = r;
+ bg.g = byte_scale(g, AS_BYTE(0.75));
+ bg.b = byte_scale(b, AS_BYTE(0.75));
+
+ return blend(white(time, x), bg);
+}
+
+static rgb_t candycane_twinkle(uint32_t time, size_t x)
+{
+ rgb_t twink = more_twinkle(time / 4, x);
+ int a = twink.a;
+
+ if (time & 0x3) {
+ // Linear interpolate.
+ int amt = time % 4;
+ a = (a * (4 - amt) + more_twinkle((time / 4) + 1, x).a * amt) / 4;
+ }
+
+ rgb_t bg = candycane_bg(time, x);
+
+ bg.a = a;
+ return bg;
}
static void reset(void)
@@ -25,4 +51,13 @@ static void reset(void)
}
__attribute__((__section__(".patterns"))) volatile static pattern_t pat =
- ((pattern_t){.get_rgb = get_rgb, .name = "CandyCane", .reset = reset});
+ ((pattern_t){.get_rgb = candycane_bg, .name = "CandyCane", .reset = reset});
+
+__attribute__((__section__(".patterns"))) volatile static pattern_t naked_pat =
+ ((pattern_t){.get_rgb = white, .name = "Naked White", .reset = reset});
+
+__attribute__((
+ __section__(".patterns"))) volatile static pattern_t candycane_twinkle_pat =
+ ((pattern_t){.get_rgb = candycane_twinkle,
+ .name = "Candycane Twinkle",
+ .reset = reset});