1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#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
}
rgb_t twinkle(uint32_t time, size_t x)
{
uint8_t time_offset = pseudo_random(x);
uint32_t adj_time = time - time_offset;
uint32_t time8 = adj_time & 0xff;
uint32_t speed = pseudo_random((adj_time >> 8) + x) & 0x3;
time8 *= speed;
uint8_t w = 0;
if (time8 <= 255) {
w = calc_w(time8);
} else {
w = 0;
}
rgb_t r;
r.r = 0xff;
r.g = 0xff;
r.b = 0xff;
r.a = 0xff - w;
return r;
}
rgb_t more_twinkle(uint32_t time, size_t x)
{
uint8_t time_offset = pseudo_random(x);
#define N 91
uint32_t adj_time = time - time_offset;
uint32_t time8 = adj_time % N;
uint32_t speed = pseudo_random((adj_time / N) + x) % 3;
time8 *= speed;
time8 += (255 - N);
uint8_t w = 0;
if (time8 <= 255) {
w = calc_w(time8);
} else {
w = 0;
}
rgb_t r;
r.r = 0xff;
r.g = 0xff;
r.b = 0xff;
r.a = 0xff - w;
return r;
}
static rgb_t get_rgb(uint32_t time, size_t x)
{
uint8_t time8 = time & 0xff;
rgb_t twink = twinkle(time, x);
rgb_t bg;
bg.color = 0;
bg.r = 0xff;
bg.g = byte_scale(byte_sin(time8 + x * 2), 0x60);
bg.b = 0;
bg.a = 0xa0;
return blend(twink, bg);
}
static rgb_t blue_twinkle(uint32_t time, size_t x)
{
rgb_t bg;
uint8_t time8 = time & 0xff;
bg.color = 0;
bg.r = byte_sin((time8 * 2 + x * 2 + 0x80) * 2);
bg.g = byte_sin(time8 + x * 2);
bg.b = 0xff;
bg.a = 0xc0;
return blend(twinkle(time, x), bg);
}
static rgb_t warm_twinkle(uint32_t time, size_t x)
{
uint8_t time8 = time & 0xff;
rgb_t twink = twinkle(time, x);
rgb_t bg;
bg.color = 0;
bg.r = 0xff;
bg.g = byte_scale(byte_sin(time8 + x * 2), 0x60);
bg.b = 0;
bg.a = twink.a;
return bg;
}
static rgb_t cool_twinkle(uint32_t time, size_t x)
{
rgb_t bg;
uint8_t time8 = time & 0xff;
rgb_t twink = twinkle(time, x);
bg.color = 0;
bg.r = byte_sin((time8 * 2 + x * 2 + 0x80) * 2);
bg.g = byte_sin(time8 + x * 2);
bg.b = 0xff;
bg.a = twink.a;
return bg;
}
static void reset(void)
{
}
__attribute__((__section__(".patterns"))) volatile static pattern_t p08_pat =
((pattern_t){.get_rgb = get_rgb, .name = "Twinkle", .reset = reset});
__attribute__((
__section__(".patterns"))) volatile static pattern_t p09_naked_pat =
((pattern_t){.get_rgb = twinkle, .name = "Naked Twinkle", .reset = reset});
__attribute__((__section__(
".patterns"))) volatile static pattern_t p10_naked_pat = ((pattern_t){
.get_rgb = warm_twinkle, .name = "Warm Twinkle", .reset = reset});
__attribute__((__section__(".patterns"))) volatile static pattern_t p11_cool_pat =
((pattern_t){
.get_rgb = cool_twinkle, .name = "Cool Twinkle", .reset = reset});
__attribute__((__section__(".patterns"))) volatile static pattern_t blue_pat =
((pattern_t){
.get_rgb = blue_twinkle, .name = "Blue Twinkle", .reset = reset});
|