forked from brimshot/quickPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqpColor.h
89 lines (55 loc) · 2.22 KB
/
qpColor.h
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
#ifndef QP_COLOR_H
#define QP_COLOR_H
enum QP_COLOR_MODE {SEQUENTIAL, RANDOM};
#include <qpPattern.h>
class qpPattern;
class qpColor {
private:
qpPattern *parentPattern;
CRGB currentColor;
// Color values
CRGBPalette16 colorPalette;
byte paletteStep = 3; // amount to jump when using palette sequentially
byte paletteIndex = 0;
CRGB *colorSet;
byte numColorsInSet = 0;
byte colorSetIndex = 0;
// Change timing
int *colorPeriodsCounter = nullptr;
unsigned int periodCountAtLastColorChange = 0;
int minColorDuration = 1;
int maxColorDuration = 0;
unsigned int currentColorDuration = 0;
int chanceToChangeColor = 0;
void setColorDuration(int minPeriods, int maxPeriods);
void updateColorPeriodically();
// Load routines
void loadNextPaletteColorRandomly();
void loadNextPaletteColorSequentially();
void loadNextColorFromSetRandomly();
void loadNextColorFromSetSequentially();
void (qpColor::*loadNextColorFunction)(); // random or sequential
void doNothing() { /* empty function for pointers to pattern update steps that do nothing as per config */ }
public:
qpColor(qpPattern *parentPattern);
// ~ Rendering
void (qpColor::*updateColorFunction)(); // periodic or nothing
void _loadNextColor(); //calls appropriate load routine
CRGB getColor() { return this->currentColor; }
CRGBPalette16 getPalette() { return this->colorPalette; }
// ~ Config
// Color sequence
qpColor &singleColor(CRGB color);
qpColor &usePalette(CRGBPalette16 palette);
qpColor &chooseColorFromPalette(CRGBPalette16 palette, QP_COLOR_MODE mode);
qpColor &setPaletteStep(byte stepSize);
qpColor &useColorSet(CRGB *colorSet, byte numElements);
qpColor &chooseColorFromSet(CRGB *colorSet, byte numElements, QP_COLOR_MODE mode);
// Timing
qpColor &changeColorEveryNTicks(int minTicks, int maxTicks = 0);
qpColor &changeColorEveryNCycles(int minCycles, int maxCycles = 0);
qpColor &changeColorEveryNFrames(int minFrames, int maxFrames = 0);
qpColor &changeColorEveryNActivations(int minActivations, int maxActivations = 0);
qpColor &withChanceToChangeColor(byte percentage);
};
#endif