diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/patterns/candycane.c | 28 | ||||
-rw-r--r-- | src/patterns/hearth.c | 28 | ||||
-rw-r--r-- | src/patterns/twinkle.c | 54 |
3 files changed, 110 insertions, 0 deletions
diff --git a/src/patterns/candycane.c b/src/patterns/candycane.c new file mode 100644 index 0000000..dbf80de --- /dev/null +++ b/src/patterns/candycane.c @@ -0,0 +1,28 @@ +#include "byte_math.h" +#include "pattern.h" + +static rgb_t get_rgb(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; +} + +static void reset(void) +{ +} + +__attribute__((__section__(".patterns"))) volatile static pattern_t pat = + ((pattern_t){.get_rgb = get_rgb, .name = "CandyCane", .reset = reset}); diff --git a/src/patterns/hearth.c b/src/patterns/hearth.c new file mode 100644 index 0000000..373562a --- /dev/null +++ b/src/patterns/hearth.c @@ -0,0 +1,28 @@ +#include "byte_math.h" +#include "pattern.h" + +static rgb_t get_rgb(uint32_t time, size_t x) +{ + int r = 0, g = 0, b = 0; + + uint8_t time8 = time & 0xff; + int w = 0 ; // calc_w(time8 + x * 10); + + r = 0xff; + g = byte_scale(byte_sin(time8 + x * 2), 0x60); + b = 0; + + 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; +} + +static void reset(void) +{ +} + +__attribute__((__section__(".patterns"))) volatile static pattern_t pat = + ((pattern_t){.get_rgb = get_rgb, .name = "Hearth", .reset = reset}); diff --git a/src/patterns/twinkle.c b/src/patterns/twinkle.c new file mode 100644 index 0000000..564a30a --- /dev/null +++ b/src/patterns/twinkle.c @@ -0,0 +1,54 @@ +#include <stdio.h> +#include "byte_math.h" +#include "pattern.h" + +static uint8_t pseudo_random(uint8_t x) { + return (1103515245 * x + 12345) & 0xFF; // & 0xFF ensures the result is 0-255 +} + + +static rgb_t get_rgb(uint32_t time, size_t x) +{ + int r = 0, g = 0, b = 0; + + uint8_t time8 = time & 0xff; + uint8_t time_offset = pseudo_random(x); + + uint32_t adjusted_time = time - time_offset; + + // The random number for this "metaframe." The metaframe is enough to show 1 + // flash. It's used to keep the same LED's from consistently repeating. + uint32_t metaframe = adjusted_time >> 8; + uint8_t rand = pseudo_random(x + metaframe); + uint8_t speed = pseudo_random(rand) % 16; + uint8_t off = pseudo_random(rand + speed); + + if (speed > 4) { + speed = 0; + } + + uint32_t w_index = ((adjusted_time - off) * speed) & 0xff; + int w = 0; + if (w_index < 255) { + w = calc_w(w_index); + } + + + r = 0xff; + g = byte_scale(byte_sin(time8 + x * 2), 0x60); + b = 0; + + 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; +} + +static void reset(void) +{ +} + +__attribute__((__section__(".patterns"))) volatile static pattern_t pat = + ((pattern_t){.get_rgb = get_rgb, .name = "Twinkle", .reset = reset}); |