Skip to content

Commit ed440d4

Browse files
authored
Merge pull request #182 from AlexxBoo/fibonacci256
Emitter Pattern
2 parents cb450e7 + d9dcbb5 commit ed440d4

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Map.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ void andPixelAR(uint8_t angle, uint8_t dAngle, uint8_t startRadius, uint8_t endR
7676
}
7777
}
7878

79-
void antialiasPixelAR(uint8_t angle, uint8_t dAngle, uint8_t startRadius, uint8_t endRadius, CRGB color)
79+
void antialiasPixelAR(uint8_t angle, uint8_t dAngle, uint8_t startRadius, uint8_t endRadius, CRGB color, CRGB leds[] = leds, int _NUM_LEDS = NUM_LEDS)
8080
{
81-
for (uint16_t i = 0; i < NUM_LEDS; i++) {
81+
for (uint16_t i = 0; i < _NUM_LEDS; i++) {
8282
uint8_t o = i;
8383

8484
uint8_t ao = angles[o];

esp8266-fastled-webserver.ino

+41
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
6767
#define LED_TYPE WS2812B
6868
#define COLOR_ORDER GRB
6969
#define NUM_LEDS 256
70+
#define NUM_LEDS_3 NUM_LEDS * 3
7071

7172
#define MILLI_AMPS 2000 // IMPORTANT: set the max milli-Amps of your power supply (4A = 4000mA)
7273
#define FRAMES_PER_SECOND 120 // here you can control the speed. With the Access Point / Web Server the animations run a bit slower.
@@ -200,6 +201,7 @@ PatternAndNameList patterns = {
200201
{ swirlFibonacci, "Swirl Fibonacci"},
201202
{ fireFibonacci, "Fire Fibonacci" },
202203
{ waterFibonacci, "Water Fibonacci" },
204+
{ emitterFibonacci, "Emitter Fibonacci" },
203205

204206
{ pacifica_loop, "Pacifica" },
205207
{ pacifica_fibonacci_loop, "Pacifica Fibonacci" },
@@ -1457,6 +1459,45 @@ void waterFibonacci() {
14571459
}
14581460
}
14591461

1462+
/**
1463+
* Emits arcs of color spreading out from the center to the edge of the disc.
1464+
*/
1465+
void emitterFibonacci() {
1466+
static CRGB ledBuffer[NUM_LEDS]; // buffer for better fade behavior
1467+
const uint8_t dAngle = 32; // angular span of the traces
1468+
const uint8_t dRadius = 12; // radial width of the traces
1469+
const uint8_t vSpeed = 16; // max speed variation
1470+
1471+
static const uint8_t eCount = 7; // Number of simultanious traces
1472+
static uint8_t angle[eCount]; // individual trace angles
1473+
static uint16_t timeOffset[eCount]; // individual offsets from beat8() function
1474+
static uint8_t speedOffset[eCount]; // individual speed offsets limited by vSpeed
1475+
static uint8_t sparkIdx = 0; // randomizer cycles through traces to spark new ones
1476+
1477+
// spark new trace
1478+
EVERY_N_MILLIS(20) {
1479+
if (random8(17) <= (speed >> 4)) { // increase change rate for higher speeds
1480+
angle[sparkIdx] = random8();
1481+
speedOffset[sparkIdx] = random8(vSpeed); // individual speed variation
1482+
timeOffset[sparkIdx] = beat8(qadd8(speed,speedOffset[sparkIdx]));
1483+
sparkIdx = addmod8(sparkIdx, 1, eCount); // continue randomizer at next spark
1484+
}
1485+
}
1486+
1487+
// fade traces
1488+
fadeToBlackBy( ledBuffer, NUM_LEDS, 6 + (speed >> 3));
1489+
1490+
// draw traces
1491+
for (uint8_t e = 0; e < eCount; e++) {
1492+
uint8_t startRadius = sub8(beat8(qadd8(speed, speedOffset[e])), timeOffset[e]);
1493+
uint8_t endRadius = add8(startRadius, dRadius + (speed>>5)); // increase radial width for higher speeds
1494+
antialiasPixelAR(angle[e], dAngle, startRadius, endRadius, ColorFromPalette(gCurrentPalette, startRadius), ledBuffer);
1495+
}
1496+
1497+
// copy buffer to actual strip
1498+
memcpy(leds, ledBuffer, NUM_LEDS_3);
1499+
}
1500+
14601501
void wheel() {
14611502
for (uint16_t i = 0; i < NUM_LEDS; i++) {
14621503
uint8_t j = beat8(speed);

0 commit comments

Comments
 (0)