Skip to content

Commit 17cfeec

Browse files
committed
Added FibonacciStars pattern.
1 parent fbfb83b commit 17cfeec

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

esp8266-fastled-webserver/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ extern const uint8_t patternCount;
155155
extern const PatternAndName patterns[];
156156

157157
extern uint8_t currentPaletteIndex;
158+
extern uint8_t gHue;
158159
extern uint8_t autoplay;
159160
extern uint8_t autoplayDuration;
160161
extern uint8_t showClock;
@@ -329,8 +330,7 @@ void colorWavesPlayground();
329330
void pacifica_fibonacci_loop();
330331
void pridePlaygroundFibonacci();
331332
void colorWavesPlaygroundFibonacci();
333+
void fibonacciStars();
332334
#endif
333335

334-
335-
336336
#endif // ESP8266_FASTLED_WEBSERVER_COMMON_H

esp8266-fastled-webserver/esp8266-fastled-webserver.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const PatternAndName patterns[] = {
121121
{ waterFibonacci, "Water Fibonacci" },
122122
{ emitterFibonacci, "Emitter Fibonacci" },
123123
{ pacifica_fibonacci_loop, "Pacifica Fibonacci" },
124+
{ fibonacciStars, "Fibonacci Stars" },
124125
#endif
125126

126127
#if HAS_COORDINATE_MAP // really a wrong name... and likely doing way more computation than necessary

0 commit comments

Comments
 (0)