@@ -124,86 +124,86 @@ void setRandomColor(byte* rgb)
124
124
*/
125
125
CRGBPalette16 generateHarmonicRandomPalette (CRGBPalette16 &basepalette)
126
126
{
127
- CHSV palettecolors[4 ]; // array of colors for the new palette
128
- uint8_t keepcolorposition = random8 (4 ); // color position of current random palette to keep
129
- palettecolors[keepcolorposition] = rgb2hsv (basepalette.entries [keepcolorposition*5 ]); // read one of the base colors of the current palette
130
- palettecolors[keepcolorposition].hue += random8 (10 )-5 ; // +/- 5 randomness of base color
131
- // generate 4 saturation and brightness value numbers
132
- // only one saturation is allowed to be below 200 creating mostly vibrant colors
133
- // only one brightness value number is allowed below 200, creating mostly bright palettes
134
-
135
- for (int i = 0 ; i < 3 ; i++) { // generate three high values
136
- palettecolors[i].saturation = random8 (200 ,255 );
137
- palettecolors[i].value = random8 (220 ,255 );
127
+ CHSV palettecolors[4 ]; // array of colors for the new palette
128
+ uint8_t keepcolorposition = hw_random8 (4 ); // color position of current random palette to keep
129
+ palettecolors[keepcolorposition] = rgb2hsv (basepalette.entries [keepcolorposition*5 ]); // read one of the base colors of the current palette
130
+ palettecolors[keepcolorposition].hue += hw_random8 (10 )-5 ; // +/- 5 randomness of base color
131
+ // generate 4 saturation and brightness value numbers
132
+ // only one saturation is allowed to be below 200 creating mostly vibrant colors
133
+ // only one brightness value number is allowed below 200, creating mostly bright palettes
134
+
135
+ for (int i = 0 ; i < 3 ; i++) { // generate three high values
136
+ palettecolors[i].saturation = hw_random8 (200 ,255 );
137
+ palettecolors[i].value = hw_random8 (220 ,255 );
138
138
}
139
- // allow one to be lower
140
- palettecolors[3 ].saturation = random8 (20 ,255 );
141
- palettecolors[3 ].value = random8 (80 ,255 );
139
+ // allow one to be lower
140
+ palettecolors[3 ].saturation = hw_random8 (20 ,255 );
141
+ palettecolors[3 ].value = hw_random8 (80 ,255 );
142
142
143
- // shuffle the arrays
143
+ // shuffle the arrays
144
144
for (int i = 3 ; i > 0 ; i--) {
145
- std::swap (palettecolors[i].saturation , palettecolors[random8 (i + 1 )].saturation );
146
- std::swap (palettecolors[i].value , palettecolors[random8 (i + 1 )].value );
145
+ std::swap (palettecolors[i].saturation , palettecolors[hw_random8 (i + 1 )].saturation );
146
+ std::swap (palettecolors[i].value , palettecolors[hw_random8 (i + 1 )].value );
147
147
}
148
148
149
- // now generate three new hues based off of the hue of the chosen current color
149
+ // now generate three new hues based off of the hue of the chosen current color
150
150
uint8_t basehue = palettecolors[keepcolorposition].hue ;
151
- uint8_t harmonics[3 ]; // hues that are harmonic but still a little random
152
- uint8_t type = random8 (5 ); // choose a harmony type
151
+ uint8_t harmonics[3 ]; // hues that are harmonic but still a little random
152
+ uint8_t type = hw_random8 (5 ); // choose a harmony type
153
153
154
154
switch (type) {
155
155
case 0 : // analogous
156
- harmonics[0 ] = basehue + random8 (30 , 50 );
157
- harmonics[1 ] = basehue + random8 (10 , 30 );
158
- harmonics[2 ] = basehue - random8 (10 , 30 );
156
+ harmonics[0 ] = basehue + hw_random8 (30 , 50 );
157
+ harmonics[1 ] = basehue + hw_random8 (10 , 30 );
158
+ harmonics[2 ] = basehue - hw_random8 (10 , 30 );
159
159
break ;
160
160
161
161
case 1 : // triadic
162
- harmonics[0 ] = basehue + 113 + random8 (15 );
163
- harmonics[1 ] = basehue + 233 + random8 (15 );
164
- harmonics[2 ] = basehue - 7 + random8 (15 );
162
+ harmonics[0 ] = basehue + 113 + hw_random8 (15 );
163
+ harmonics[1 ] = basehue + 233 + hw_random8 (15 );
164
+ harmonics[2 ] = basehue - 7 + hw_random8 (15 );
165
165
break ;
166
166
167
167
case 2 : // split-complementary
168
- harmonics[0 ] = basehue + 145 + random8 (10 );
169
- harmonics[1 ] = basehue + 205 + random8 (10 );
170
- harmonics[2 ] = basehue - 5 + random8 (10 );
168
+ harmonics[0 ] = basehue + 145 + hw_random8 (10 );
169
+ harmonics[1 ] = basehue + 205 + hw_random8 (10 );
170
+ harmonics[2 ] = basehue - 5 + hw_random8 (10 );
171
171
break ;
172
172
173
173
case 3 : // square
174
- harmonics[0 ] = basehue + 85 + random8 (10 );
175
- harmonics[1 ] = basehue + 175 + random8 (10 );
176
- harmonics[2 ] = basehue + 265 + random8 (10 );
174
+ harmonics[0 ] = basehue + 85 + hw_random8 (10 );
175
+ harmonics[1 ] = basehue + 175 + hw_random8 (10 );
176
+ harmonics[2 ] = basehue + 265 + hw_random8 (10 );
177
177
break ;
178
178
179
179
case 4 : // tetradic
180
- harmonics[0 ] = basehue + 80 + random8 (20 );
181
- harmonics[1 ] = basehue + 170 + random8 (20 );
182
- harmonics[2 ] = basehue - 15 + random8 (30 );
180
+ harmonics[0 ] = basehue + 80 + hw_random8 (20 );
181
+ harmonics[1 ] = basehue + 170 + hw_random8 (20 );
182
+ harmonics[2 ] = basehue - 15 + hw_random8 (30 );
183
183
break ;
184
184
}
185
185
186
- if (random8 () < 128 ) {
187
- // 50:50 chance of shuffling hues or keep the color order
186
+ if (hw_random8 () < 128 ) {
187
+ // 50:50 chance of shuffling hues or keep the color order
188
188
for (int i = 2 ; i > 0 ; i--) {
189
- std::swap (harmonics[i], harmonics[random8 (i + 1 )]);
189
+ std::swap (harmonics[i], harmonics[hw_random8 (i + 1 )]);
190
190
}
191
191
}
192
192
193
- // now set the hues
193
+ // now set the hues
194
194
int j = 0 ;
195
195
for (int i = 0 ; i < 4 ; i++) {
196
- if (i==keepcolorposition) continue ; // skip the base color
196
+ if (i==keepcolorposition) continue ; // skip the base color
197
197
palettecolors[i].hue = harmonics[j];
198
198
j++;
199
199
}
200
200
201
201
bool makepastelpalette = false ;
202
- if (random8 () < 25 ) { // ~10% chance of desaturated 'pastel' colors
202
+ if (hw_random8 () < 25 ) { // ~10% chance of desaturated 'pastel' colors
203
203
makepastelpalette = true ;
204
204
}
205
205
206
- // apply saturation & gamma correction
206
+ // apply saturation & gamma correction
207
207
CRGB RGBpalettecolors[4 ];
208
208
for (int i = 0 ; i < 4 ; i++) {
209
209
if (makepastelpalette && palettecolors[i].saturation > 180 ) {
@@ -219,12 +219,12 @@ CRGBPalette16 generateHarmonicRandomPalette(CRGBPalette16 &basepalette)
219
219
RGBpalettecolors[3 ]);
220
220
}
221
221
222
- CRGBPalette16 generateRandomPalette () // generate fully random palette
222
+ CRGBPalette16 generateRandomPalette () // generate fully random palette
223
223
{
224
- return CRGBPalette16 (CHSV (random8 (), random8 (160 , 255 ), random8 (128 , 255 )),
225
- CHSV (random8 (), random8 (160 , 255 ), random8 (128 , 255 )),
226
- CHSV (random8 (), random8 (160 , 255 ), random8 (128 , 255 )),
227
- CHSV (random8 (), random8 (160 , 255 ), random8 (128 , 255 )));
224
+ return CRGBPalette16 (CHSV (hw_random8 (), hw_random8 (160 , 255 ), hw_random8 (128 , 255 )),
225
+ CHSV (hw_random8 (), hw_random8 (160 , 255 ), hw_random8 (128 , 255 )),
226
+ CHSV (hw_random8 (), hw_random8 (160 , 255 ), hw_random8 (128 , 255 )),
227
+ CHSV (hw_random8 (), hw_random8 (160 , 255 ), hw_random8 (128 , 255 )));
228
228
}
229
229
230
230
void hsv2rgb (const CHSV32& hsv, uint32_t & rgb) // convert HSV (16bit hue) to RGB (32bit with white = 0)
0 commit comments