Pixie Chroma
Documentation for the easiest 5x7 LED displays for Arduino!
pixie_animations.cpp
Go to the documentation of this file.
1
10#include "pixie_animations.h"
11
12void ANIMATION_NULL( PixieChroma* _p, float delta ){
13 // It does nothing, but it does nothing REALLY WELL! You can enable this
14 // empty function with pix.set_animation(ANIMATION_NULL) to manually control color when you want
15}
16
17
18void ANIMATION_STATIC( PixieChroma* _p, float delta ){
19 for( uint16_t x = 0; x < _p->matrix_width; x++ ){
20 float progress = float( x / float( _p->matrix_width + 4 ) );
21 CRGB col = ColorFromPalette( _p->current_palette, progress*255 );
22 for( uint16_t y = 0; y < _p->matrix_height; y++ ){
23 uint16_t index = _p->xy( x, y );
24 _p->color_map[index] = col;
25 }
26 }
27}
28
29
30void _PALETTE_SHIFT( PixieChroma* _p, int8_t amount, float delta ){
31 static float iter = 0;
32
33 for( uint16_t x = 0; x < _p->matrix_width; x++ ){
34 float progress = float( x / float( _p->matrix_width + 4 ) );
35 CRGB col = ColorFromPalette( _p->current_palette, progress*255 + iter );
36 for( uint16_t y = 0; y < _p->matrix_height; y++ ){
37 uint16_t index = _p->xy( x, y );
38 _p->color_map[index] = col;
39 }
40 }
41
42 iter += amount * _p->animation_speed * delta;
43}
44
45
47 _PALETTE_SHIFT( _p, 4, delta );
48}
49
50
52 _PALETTE_SHIFT( _p, -4, delta );
53}
54
55
56void ANIMATION_GLITTER( PixieChroma* _p, float delta ){
57 _p->color_dim( 16 ); // Fade to black by 6.25%;
58
59 for( uint16_t x = 0; x < _p->matrix_width; x++ ){
60 float progress = float( x / float( _p->matrix_width + 4 ) );
61 for( uint16_t y = 0; y < _p->matrix_height; y++ ){
62 if( random8() <= 32 ){ // 12.5% chance
63 uint16_t index = _p->xy( x, y );
64 CRGB col = ColorFromPalette( _p->current_palette, progress*255 );
65 _p->color_map[index] = col;
66 }
67 }
68 }
69}
70
71
72void _PENDULUM( PixieChroma* _p, float center_position, float sway_width ){
73 center_position *= sway_width;
74
75 for( uint16_t x = 0; x < _p->matrix_width; x++ ){
76 float progress = float( x / float( _p->matrix_width + 4 ) );
77 float palette_index = ( progress*255 ) + center_position;
78
79 if( palette_index < 0 ){
80 palette_index = 0;
81 }
82 else if( palette_index > 255 ){
83 palette_index = 255;
84 }
85
86 CRGB col = ColorFromPalette( _p->current_palette, uint8_t(palette_index) );
87 for( uint16_t y = 0; y < _p->matrix_height; y++ ){
88 uint16_t index = _p->xy( x, y );
89 _p->color_map[index] = col;
90 }
91 }
92}
93
94void ANIMATION_PENDULUM( PixieChroma* _p, float delta ){
95 float center_position = beatsin8(60)-128;
96 _PENDULUM( _p, center_position, 0.5 );
97}
98
99
100void ANIMATION_PENDULUM_WIDE( PixieChroma* _p, float delta ){
101 float center_position = beatsin8(60)-128;
102 _PENDULUM( _p, center_position, 1.0);
103}
104
105
106CRGBPalette16 make_gradient(CRGB col1, CRGB col2){
107 const uint8_t gradient[] = {
108 0, col1.r, col1.g, col1.b,
109 255, col2.r, col2.g, col2.b
110 };
111 CRGBPalette16 pal;
112 pal.loadDynamicGradientPalette(gradient);
113
114 return pal;
115}
116
117CRGBPalette16 make_gradient(CRGB col1, CRGB col2, CRGB col3){
118 const uint8_t gradient[] = {
119 0, col1.r, col1.g, col1.b,
120 127, col2.r, col2.g, col2.b,
121 255, col3.r, col3.g, col3.b
122 };
123 CRGBPalette16 pal;
124 pal.loadDynamicGradientPalette(gradient);
125
126 return pal;
127}
128
129CRGBPalette16 make_gradient(CRGB col1, CRGB col2, CRGB col3, CRGB col4){
130 const uint8_t gradient[] = {
131 0, col1.r, col1.g, col1.b,
132 85, col2.r, col2.g, col2.b,
133 170, col3.r, col3.g, col3.b,
134 255, col4.r, col4.g, col4.b
135 };
136 CRGBPalette16 pal;
137 pal.loadDynamicGradientPalette(gradient);
138
139 return pal;
140}
141
142CRGBPalette16 make_gradient(CRGB col1, CRGB col2, CRGB col3, CRGB col4, CRGB col5){
143 const uint8_t gradient[] = {
144 0, col1.r, col1.g, col1.b,
145 63, col2.r, col2.g, col2.b,
146 127, col3.r, col3.g, col3.b,
147 191, col4.r, col4.g, col4.b,
148 255, col5.r, col5.g, col5.b
149 };
150 CRGBPalette16 pal;
151 pal.loadDynamicGradientPalette(gradient);
152
153 return pal;
154}
155
156CRGBPalette16 make_gradient(CRGB col1, CRGB col2, CRGB col3, CRGB col4, CRGB col5, CRGB col6){
157 const uint8_t gradient[] = {
158 0, col1.r, col1.g, col1.b,
159 51, col2.r, col2.g, col2.b,
160 102, col3.r, col3.g, col3.b,
161 153, col4.r, col4.g, col4.b,
162 204, col5.r, col5.g, col5.b,
163 255, col6.r, col6.g, col6.b
164 };
165 CRGBPalette16 pal;
166 pal.loadDynamicGradientPalette(gradient);
167
168 return pal;
169}
170
171CRGBPalette16 make_gradient(CRGB col1, CRGB col2, CRGB col3, CRGB col4, CRGB col5, CRGB col6, CRGB col7){
172 const uint8_t gradient[] = {
173 0, col1.r, col1.g, col1.b,
174 42, col2.r, col2.g, col2.b,
175 84, col3.r, col3.g, col3.b,
176 126, col4.r, col4.g, col4.b,
177 168, col5.r, col5.g, col5.b,
178 210, col6.r, col6.g, col6.b,
179 255, col7.r, col7.g, col7.b
180 };
181 CRGBPalette16 pal;
182 pal.loadDynamicGradientPalette(gradient);
183
184 return pal;
185}
186
187CRGBPalette16 make_gradient(CRGB col1, CRGB col2, CRGB col3, CRGB col4, CRGB col5, CRGB col6, CRGB col7, CRGB col8){
188 const uint8_t gradient[] = {
189 0, col1.r, col1.g, col1.b,
190 36, col2.r, col2.g, col2.b,
191 72, col3.r, col3.g, col3.b,
192 108, col4.r, col4.g, col4.b,
193 144, col5.r, col5.g, col5.b,
194 180, col6.r, col6.g, col6.b,
195 216, col7.r, col7.g, col7.b,
196 255, col8.r, col8.g, col8.b
197 };
198 CRGBPalette16 pal;
199 pal.loadDynamicGradientPalette(gradient);
200
201 return pal;
202}
This is the software documentation for using Pixie Chroma functions on Arduino! For full example usag...
float animation_speed
Used by animation functions to scale the apparent speed of animation.
CRGB * color_map
Contains the entire color map, including "invisible" areas.
uint16_t matrix_width
Stores the final width of the matrix, including invisible pixels.
CRGBPalette16 current_palette
The current FastLED CRGBPalette16 used for animations.
uint16_t xy(int32_t x, int32_t y, bool wrap=false)
This function returns the 1D color_map / mask index of a given 2D coordinate in the display matrix.
void color_dim(uint8_t amount)
Darkens the color buffer by an 8-bit amount.
uint16_t matrix_height
Stores the final height of the matrix, including invisible pixels.
void _PENDULUM(PixieChroma *_p, float center_position, float sway_width)
Internal animation that sways the current color palette left and right with a sine function at 1Hz in...
CRGBPalette16 make_gradient(CRGB col1, CRGB col2)
Converts a set of CRGB colors to a gradient, and creates a color palette from that gradient.
void ANIMATION_PALETTE_SHIFT_RIGHT(PixieChroma *_p, float delta)
Shows the current color palette, while constantly shifting it to the right.
void ANIMATION_STATIC(PixieChroma *_p, float delta)
Shows the current color palette without animation.
void ANIMATION_PALETTE_SHIFT_LEFT(PixieChroma *_p, float delta)
Shows the current color palette, while constantly shifting it to the left.
void ANIMATION_NULL(PixieChroma *_p, float delta)
It does nothing, but it does nothing REALLY WELL! You can enable this empty function with pix....
void ANIMATION_PENDULUM_WIDE(PixieChroma *_p, float delta)
Sways the current color palette left and right with a sine function at 1Hz intervals....
void ANIMATION_PENDULUM(PixieChroma *_p, float delta)
Sways the current color palette left and right with a sine function at 1Hz intervals.
void ANIMATION_GLITTER(PixieChroma *_p, float delta)
Shows the current color palette with a sparkling effect.
void _PALETTE_SHIFT(PixieChroma *_p, int8_t amount, float delta)
Internal animation, shifts the color palette a fixed amount on each run.