1
+ /*
2
+ ESP8266 + FastLED Web Server: https://github.com/jasoncoon/esp8266-fastled-webserver
3
+ Copyright (C) 2016 Jason Coon
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ #include " common.h"
20
+
21
+ #if IS_FIBONACCI
22
+
23
+ // Fibonacci Stars pattern by Jason Coon
24
+ // Draws shooting stars radiating outward from the center, along Fibonacci spiral lines.
25
+ void fibonacciStarsWithOffset (uint16_t stars[], uint8_t starCount, uint8_t offset = 21 , bool setup = false , bool move = false )
26
+ {
27
+ // use a number from the Fibonacci sequence for offset to follow a spiral out from the center
28
+
29
+ for (uint8_t i = 0 ; i < starCount; i++)
30
+ {
31
+ if (setup || stars[i] >= NUM_PIXELS)
32
+ {
33
+ // reset star
34
+ stars[i] = random8 (offset - 1 );
35
+ }
36
+
37
+ uint16_t index = fibonacciToPhysical[stars[i]];
38
+
39
+ // draw the star
40
+ leds[index ] = ColorFromPalette (gCurrentPalette , stars[i] - gHue ); // i * (240 / starCount)
41
+ }
42
+
43
+ // move the stars
44
+ if (move)
45
+ {
46
+ for (uint8_t i = 0 ; i < starCount; i++)
47
+ {
48
+ stars[i] = stars[i] + offset;
49
+ }
50
+ }
51
+ }
52
+
53
+ const uint8_t starCount = NUM_PIXELS >= 256 ? 4 : 2 ;
54
+
55
+ void fibonacciStars8 (bool setup = false , bool move = false )
56
+ {
57
+ static uint16_t stars[starCount];
58
+ fibonacciStarsWithOffset (stars, starCount, 8 , setup, move);
59
+ }
60
+
61
+ void fibonacciStars13 (bool setup = false , bool move = false )
62
+ {
63
+ static uint16_t stars[starCount];
64
+ fibonacciStarsWithOffset (stars, starCount, 13 , setup, move);
65
+ }
66
+
67
+ void fibonacciStars21 (bool setup = false , bool move = false )
68
+ {
69
+ static uint16_t stars[starCount];
70
+ fibonacciStarsWithOffset (stars, starCount, 21 , setup, move);
71
+ }
72
+
73
+ void fibonacciStars34 (bool setup = false , bool move = false )
74
+ {
75
+ static uint16_t stars[starCount];
76
+ fibonacciStarsWithOffset (stars, starCount, 34 , setup, move);
77
+ }
78
+
79
+ void fibonacciStars55 (bool setup = false , bool move = false ) {
80
+ static uint16_t stars[starCount];
81
+ fibonacciStarsWithOffset (stars, starCount, 55 , setup, move);
82
+ }
83
+
84
+ void fibonacciStars89 (bool setup = false , bool move = false ) {
85
+ static uint16_t stars[starCount];
86
+ fibonacciStarsWithOffset (stars, starCount, 89 , setup, move);
87
+ }
88
+
89
+ // called from Arduino loop
90
+ void fibonacciStars ()
91
+ {
92
+ bool move = false ;
93
+ static bool setup = true ;
94
+ fadeToBlackBy (leds, NUM_PIXELS, 8 );
95
+
96
+ EVERY_N_MILLIS (60 )
97
+ {
98
+ move = true ;
99
+ }
100
+
101
+ if (NUM_PIXELS >= 128 ) {
102
+ fibonacciStars8 (setup, move);
103
+ fibonacciStars13 (setup, move);
104
+ } else if (NUM_PIXELS >= 256 ) {
105
+ fibonacciStars13 (setup, move);
106
+ fibonacciStars21 (setup, move);
107
+ fibonacciStars34 (setup, move);
108
+ } else if (NUM_PIXELS >= 1024 ) {
109
+ fibonacciStars34 (setup, move);
110
+ fibonacciStars55 (setup, move);
111
+ fibonacciStars89 (setup, move);
112
+ }
113
+ setup = false ;
114
+ }
115
+
116
+ #endif
0 commit comments