Skip to content

Instantly share code, notes, and snippets.

@jasoncoon
Last active March 15, 2022 13:57
Show Gist options
  • Save jasoncoon/4fd795d0a90037838eb6b46e8ad312c0 to your computer and use it in GitHub Desktop.
Save jasoncoon/4fd795d0a90037838eb6b46e8ad312c0 to your computer and use it in GitHub Desktop.
Star pattern for Fibonacci256: https://www.tindie.com/products/19429
// Fibonacci Stars pattern by Jason Coon
// For Fibonacci256: https://www.tindie.com/products/19429
// Meant for use in this sketch: https://github.com/jasoncoon/esp8266-fastled-webserver/tree/fibonacci256
// Draws shooting stars radiating outward from the center, along Fibonacci spiral lines.
void fibonacciStarsWithOffset(uint16_t stars[], uint8_t starCount, uint8_t offset = 21, bool setup = false, bool move = false) {
// use a number from the Fibonacci sequence for offset to follow a spiral out from the center
for (uint8_t i = 0; i < starCount; i++) {
if (setup || stars[i] >= NUM_LEDS) {
// reset star
stars[i] = random8(offset - 1);
}
uint16_t index = fibonacciToPhysical[stars[i]];
// draw the star
leds[index] = ColorFromPalette(currentPalette, stars[i] + gHue); // i * (240 / starCount)
}
// move the stars
if(move) {
for (uint8_t i = 0; i < starCount; i++) {
stars[i] = stars[i] + offset;
}
}
}
const uint8_t starCount = 4;
void fibonacciStars13(bool setup = false, bool move = false) {
static uint16_t stars[starCount];
fibonacciStarsWithOffset(stars, starCount, 13, setup, move);
}
void fibonacciStars21(bool setup = false, bool move = false) {
static uint16_t stars[starCount];
fibonacciStarsWithOffset(stars, starCount, 21, setup, move);
}
void fibonacciStars34(bool setup = false, bool move = false) {
static uint16_t stars[starCount];
fibonacciStarsWithOffset(stars, starCount, 34, setup, move);
}
// called from Arduino loop
void fibonacciStars() {
bool move = false;
static bool setup = true;
fadeToBlackBy( leds, NUM_LEDS, 8);
EVERY_N_MILLIS(60) {
move = true;
}
fibonacciStars13(setup, move);
fibonacciStars21(setup, move);
fibonacciStars34(setup, move);
setup = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment