aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorEmil Muratov <gpm@hotplug.ru>2020-12-02 22:39:03 +0300
committerEmil Muratov <gpm@hotplug.ru>2020-12-02 22:39:03 +0300
commit2d38f96722486c8f65f61ada8ce8cf8563a7f974 (patch)
treed64bbfad2f147bff280b1b0e2f72d4930d10c163 /examples
parentba589028433008a4bb6d71275c63a8424a0fa5d4 (diff)
some more fixes for Aurora effects
Signed-off-by: Emil Muratov <gpm@hotplug.ru>
Diffstat (limited to 'examples')
-rw-r--r--examples/AuroraDemo/AuroraDemo.ino2
-rw-r--r--examples/AuroraDemo/Effects.h59
-rw-r--r--examples/AuroraDemo/PatternInfinity.h7
-rw-r--r--examples/AuroraDemo/PatternPendulumWave.h20
-rw-r--r--examples/AuroraDemo/PatternSpiro.h2
-rw-r--r--examples/AuroraDemo/PatternSwirl.h15
-rw-r--r--examples/AuroraDemo/Patterns.h14
7 files changed, 72 insertions, 47 deletions
diff --git a/examples/AuroraDemo/AuroraDemo.ino b/examples/AuroraDemo/AuroraDemo.ino
index d3f7978..a85d524 100644
--- a/examples/AuroraDemo/AuroraDemo.ino
+++ b/examples/AuroraDemo/AuroraDemo.ino
@@ -99,7 +99,7 @@ void loop()
}
if (fps_timer + 1000 < millis()){
- Serial.printf_P(PSTR("Effect fps: %d\n"), fps);
+ Serial.printf_P(PSTR("Effect fps: %ld\n"), fps);
fps_timer = millis();
fps = 0;
}
diff --git a/examples/AuroraDemo/Effects.h b/examples/AuroraDemo/Effects.h
index 312e05c..d1af415 100644
--- a/examples/AuroraDemo/Effects.h
+++ b/examples/AuroraDemo/Effects.h
@@ -42,6 +42,9 @@ const int MATRIX_CENTER_Y = MATRIX_HEIGHT / 2;
const uint16_t NUM_LEDS = (MATRIX_WIDTH * MATRIX_HEIGHT) + 1; // one led spare to capture out of bounds
+// forward declaration
+uint16_t XY16( uint16_t x, uint16_t y);
+
/* Convert x,y co-ordinate to flat array index.
* x and y positions start from 0, so must not be >= 'real' panel width or height
* (i.e. 64 pixels or 32 pixels.). Max value: MATRIX_WIDTH-1 etc.
@@ -49,15 +52,11 @@ const uint16_t NUM_LEDS = (MATRIX_WIDTH * MATRIX_HEIGHT) + 1; // one led spare t
*/
uint16_t XY( uint8_t x, uint8_t y)
{
- if( x >= MATRIX_WIDTH) return 0;
- if( y >= MATRIX_HEIGHT) return 0;
-
- return (y * MATRIX_WIDTH) + x + 1; // everything offset by one to capute out of bounds stuff - never displayed by ShowFrame()
-
+ return XY16(x, y);
}
/**
- * This one is for 256+ matrixes
+ * The one for 256+ matrixes
* otherwise this:
* for (uint8_t i = 0; i < MATRIX_WIDTH; i++) {}
* turns into an infinite loop
@@ -65,8 +64,8 @@ uint16_t XY( uint8_t x, uint8_t y)
uint16_t XY16( uint16_t x, uint16_t y)
{
if( x >= MATRIX_WIDTH) return 0;
- if( y >= MATRIX_HEIGHT) return 0;
-
+ if( y >= MATRIX_HEIGHT) return 0;
+
return (y * MATRIX_WIDTH) + x + 1; // everything offset by one to capute out of bounds stuff - never displayed by ShowFrame()
}
@@ -106,7 +105,8 @@ uint32_t noise_z;
uint32_t noise_scale_x;
uint32_t noise_scale_y;
-uint8_t noise[MATRIX_WIDTH][MATRIX_HEIGHT];
+//uint8_t noise[MATRIX_WIDTH][MATRIX_HEIGHT];
+uint8_t **noise = nullptr; // we will allocate mem later
uint8_t noisesmoothing;
class Effects {
@@ -114,14 +114,27 @@ public:
CRGB *leds;
//CRGB leds[NUM_LEDS];
//CRGB leds2[NUM_LEDS]; // Faptastic: getting rid of this and any dependant effects or algos. to save memory 24*64*32 bytes of ram (50k).
-
+
Effects(){
- // we do dynamic allocation for leds buffer, otherwise esp32 toolchain can't link static arrays of this size for 256+ matrixes
+ // we do dynamic allocation for leds buffer, otherwise esp32 toolchain can't link static arrays of such a big size for 256+ matrixes
leds = (CRGB *)malloc(NUM_LEDS * sizeof(CRGB));
+
+ // allocate mem for noise effect
+ // (there should be some guards for malloc errors eventually)
+ noise = (uint8_t **)malloc(MATRIX_WIDTH * sizeof(uint8_t *));
+ for (int i = 0; i < MATRIX_WIDTH; ++i) {
+ noise[i] = (uint8_t *)malloc(MATRIX_HEIGHT * sizeof(uint8_t));
+ }
+
ClearFrame();
+ matrix.clearScreen();
}
~Effects(){
free(leds);
+ for (int i = 0; i < MATRIX_WIDTH; ++i) {
+ free(noise[i]);
+ }
+ free(noise);
}
/* The only 'framebuffer' we have is what is contained in the leds and leds2 variables.
@@ -136,7 +149,7 @@ public:
leds[XY(x, y)] = color;
//matrix.drawPixelRGB888(x, y, color.r, color.g, color.b);
}
-
+
// write one pixel with the specified color from the current palette to coordinates
void Pixel(int x, int y, uint8_t colorIndex) {
leds[XY(x, y)] = ColorFromCurrentPalette(colorIndex);
@@ -157,15 +170,14 @@ public:
// backgroundLayer.swapBuffers();
// leds = (CRGB*) backgroundLayer.backBuffer();
// LEDS.countFPS();
-
- for (int y=0;y<MATRIX_HEIGHT; y++)
- for (int x=0;x<MATRIX_WIDTH; x++)
- {
- //Serial.printf("\r\nFlushing x, y coord %d, %d", x, y);
- //display.drawPixelRGB888( x, 31-y, tmp_led.r, tmp_led.g, tmp_led.b);
- matrix.drawPixelRGB888( x, y, leds[XY16(x,y)].r, leds[XY16(x,y)].g, leds[XY16(x,y)].b);
- } // end loop to copy fast led to the dma matrix
+ for (int y=0; y<MATRIX_HEIGHT; ++y){
+ for (int x=0; x<MATRIX_WIDTH; ++x){
+ //Serial.printf("Flushing x, y coord %d, %d\n", x, y);
+ uint16_t _pixel = XY16(x,y);
+ matrix.drawPixelRGB888( x, y, leds[_pixel].r, leds[_pixel].g, leds[_pixel].b);
+ } // end loop to copy fast led to the dma matrix
+ }
}
// scale the brightness of the screenbuffer down
@@ -180,7 +192,6 @@ public:
void ClearFrame()
{
memset(leds, 0x00, NUM_LEDS * sizeof(CRGB)); // flush
- matrix.clearScreen();
}
@@ -419,8 +430,8 @@ public:
// copy one diagonal triangle into the other one within a 16x16
void Caleidoscope3() {
- for (int x = 0; x <= MATRIX_CENTRE_X; x++) {
- for (int y = 0; y <= x; y++) {
+ for (int x = 0; x <= MATRIX_CENTRE_X && x < MATRIX_HEIGHT; x++) {
+ for (int y = 0; y <= x && y<MATRIX_HEIGHT; y++) {
leds[XY16(x, y)] = leds[XY16(y, x)];
}
}
@@ -438,7 +449,7 @@ public:
// copy one diagonal triangle into the other one within a 8x8
void Caleidoscope5() {
for (int x = 0; x < MATRIX_WIDTH / 4; x++) {
- for (int y = 0; y <= x; y++) {
+ for (int y = 0; y <= x && y<=MATRIX_HEIGHT; y++) {
leds[XY16(x, y)] = leds[XY16(y, x)];
}
}
diff --git a/examples/AuroraDemo/PatternInfinity.h b/examples/AuroraDemo/PatternInfinity.h
index 92f6b9c..0c068ad 100644
--- a/examples/AuroraDemo/PatternInfinity.h
+++ b/examples/AuroraDemo/PatternInfinity.h
@@ -31,7 +31,9 @@ public:
unsigned int drawFrame() {
// dim all pixels on the display slightly
// to 250/255 (98%) of their current brightness
- effects.DimAll(250); effects.ShowFrame();
+ blur2d(effects.leds, MATRIX_WIDTH > 255 ? 255 : MATRIX_WIDTH, MATRIX_HEIGHT > 255 ? 255 : MATRIX_HEIGHT, 250);
+ // effects.DimAll(250); effects.ShowFrame();
+
// the Effects class has some sample oscillators
// that move from 0 to 255 at different speeds
@@ -51,7 +53,8 @@ public:
// draw a pixel at x,y using a color from the current palette
effects.Pixel(x, y, hue);
- return 15;
+ effects.ShowFrame();
+ return 30;
}
};
diff --git a/examples/AuroraDemo/PatternPendulumWave.h b/examples/AuroraDemo/PatternPendulumWave.h
index b0ae99c..08fd5b7 100644
--- a/examples/AuroraDemo/PatternPendulumWave.h
+++ b/examples/AuroraDemo/PatternPendulumWave.h
@@ -34,6 +34,12 @@
#ifndef PatternPendulumWave_H
#define PatternPendulumWave_H
+#define WAVE_BPM 25
+#define AMP_BPM 2
+#define SKEW_BPM 4
+#define WAVE_TIMEMINSKEW MATRIX_WIDTH/8
+#define WAVE_TIMEMAXSKEW MATRIX_WIDTH/2
+
class PatternPendulumWave : public Drawable {
public:
PatternPendulumWave() {
@@ -41,15 +47,19 @@ class PatternPendulumWave : public Drawable {
}
unsigned int drawFrame() {
- effects.DimAll(170); effects.ShowFrame();
+ effects.ClearFrame();
- for (int x = 0; x < MATRIX_WIDTH; x++)
+ for (int x = 0; x < MATRIX_WIDTH; ++x)
{
- uint8_t y = beatsin8(x + MATRIX_WIDTH, 0, MATRIX_HEIGHT);
+ uint16_t amp = beatsin16(AMP_BPM, MATRIX_HEIGHT/8, MATRIX_HEIGHT-1);
+ uint16_t offset = (MATRIX_HEIGHT - beatsin16(AMP_BPM, 0, MATRIX_HEIGHT))/2;
+
+ uint8_t y = beatsin16(WAVE_BPM, 0, amp, x*beatsin16(SKEW_BPM, WAVE_TIMEMINSKEW, WAVE_TIMEMAXSKEW)) + offset;
+
effects.drawBackgroundFastLEDPixelCRGB(x, y, effects.ColorFromCurrentPalette(x * 7));
}
-
- return 10;
+ effects.ShowFrame();
+ return 20;
}
};
diff --git a/examples/AuroraDemo/PatternSpiro.h b/examples/AuroraDemo/PatternSpiro.h
index ee0d03e..c41a3c6 100644
--- a/examples/AuroraDemo/PatternSpiro.h
+++ b/examples/AuroraDemo/PatternSpiro.h
@@ -51,7 +51,7 @@ class PatternSpiro : public Drawable {
};
unsigned int drawFrame() {
- effects.DimAll(1);
+ blur2d(effects.leds, MATRIX_WIDTH > 255 ? 255 : MATRIX_WIDTH, MATRIX_HEIGHT > 255 ? 255 : MATRIX_HEIGHT, 192);
boolean change = false;
diff --git a/examples/AuroraDemo/PatternSwirl.h b/examples/AuroraDemo/PatternSwirl.h
index d6df5ef..e3baf2f 100644
--- a/examples/AuroraDemo/PatternSwirl.h
+++ b/examples/AuroraDemo/PatternSwirl.h
@@ -44,27 +44,28 @@ class PatternSwirl : public Drawable {
// Note that we never actually clear the matrix, we just constantly
// blur it repeatedly. Since the blurring is 'lossy', there's
// an automatic trend toward black -- by design.
- uint8_t blurAmount = beatsin8(2, 10, 255);
+ uint8_t blurAmount = beatsin8(2, 10, 255)
#if FASTLED_VERSION >= 3001000
- blur2d(effects.leds, MATRIX_WIDTH, MATRIX_HEIGHT, blurAmount);
+ blur2d(effects.leds, MATRIX_WIDTH > 255 ? 255 : MATRIX_WIDTH, MATRIX_HEIGHT > 255 ? 255 : MATRIX_HEIGHT, blurAmount);
#else
effects.DimAll(blurAmount);
#endif
// Use two out-of-sync sine waves
- uint8_t i = beatsin8(13, borderWidth, MATRIX_HEIGHT - borderWidth);
- uint8_t j = beatsin8(27, borderWidth, MATRIX_WIDTH - borderWidth);
+ uint8_t i = beatsin8(256/MATRIX_HEIGHT, borderWidth, MATRIX_WIDTH - borderWidth);
+ uint8_t j = beatsin8(2048/MATRIX_WIDTH, borderWidth, MATRIX_HEIGHT - borderWidth);
+
// Also calculate some reflections
uint8_t ni = (MATRIX_WIDTH - 1) - i;
- uint8_t nj = (MATRIX_WIDTH - 1) - j;
+ uint8_t nj = (MATRIX_HEIGHT - 1) - j;
// The color of each point shifts over time, each at a different speed.
uint16_t ms = millis();
effects.leds[XY(i, j)] += effects.ColorFromCurrentPalette(ms / 11);
- effects.leds[XY(j, i)] += effects.ColorFromCurrentPalette(ms / 13);
+ //effects.leds[XY(j, i)] += effects.ColorFromCurrentPalette(ms / 13); // this doesn't work for non-square matrixes
effects.leds[XY(ni, nj)] += effects.ColorFromCurrentPalette(ms / 17);
- effects.leds[XY(nj, ni)] += effects.ColorFromCurrentPalette(ms / 29);
+ //effects.leds[XY(nj, ni)] += effects.ColorFromCurrentPalette(ms / 29); // this doesn't work for non-square matrixes
effects.leds[XY(i, nj)] += effects.ColorFromCurrentPalette(ms / 37);
effects.leds[XY(ni, j)] += effects.ColorFromCurrentPalette(ms / 41);
diff --git a/examples/AuroraDemo/Patterns.h b/examples/AuroraDemo/Patterns.h
index e141146..370a4c2 100644
--- a/examples/AuroraDemo/Patterns.h
+++ b/examples/AuroraDemo/Patterns.h
@@ -56,7 +56,7 @@
#include "PatternInfinity.h"
#include "PatternPlasma.h"
#include "PatternSnake.h"
-//#include "PatternInvaders.h" // Doesn't seem to work, omitting.
+#include "PatternInvaders.h"
//#include "PatternCube.h" // Doesn't seem to work, omitting.
//#include "PatternFire.h" // Doesn't seem to work, omitting.
#include "PatternLife.h"
@@ -81,7 +81,7 @@ class Patterns : public Playlist {
PatternSwirl swirl;
PatternPendulumWave pendulumWave;
PatternFlowField flowField;
- // PatternIncrementalDrift incrementalDrift;
+ PatternIncrementalDrift incrementalDrift;
// PatternIncrementalDrift2 incrementalDrift2;
PatternMunch munch;
PatternElectricMandala electricMandala;
@@ -93,7 +93,7 @@ class Patterns : public Playlist {
PatternFlock flock;
PatternInfinity infinity;
PatternPlasma plasma;
- // PatternInvadersSmall invadersSmall;
+ PatternInvadersSmall invadersSmall;
// PatternInvadersMedium invadersMedium;
// PatternInvadersLarge invadersLarge;
PatternSnake snake;
@@ -114,7 +114,7 @@ class Patterns : public Playlist {
//const static int PATTERN_COUNT = 37;
- const static int PATTERN_COUNT = 16;
+ const static int PATTERN_COUNT = 17;
Drawable* shuffledItems[PATTERN_COUNT];
@@ -133,13 +133,13 @@ class Patterns : public Playlist {
&flowField,
&pendulumWave, //11 ok
- // &incrementalDrift, //12 ok
+ &incrementalDrift, //12 ok
// &incrementalDrift2, // 13 fail
&munch, // 14 ok
&electricMandala, // 15 ok
// &spin, // 16 ok but repeditivev
&simplexNoise, // 17 - cool!
- &wave, // 18 ok
+ // &wave, // 18 ok (can't work with 256+ matrix due to uint8_t vars)
// &rainbowFlag, //20 // fail
&attract, // 21 ok
&swirl, // 22
@@ -147,7 +147,7 @@ class Patterns : public Playlist {
&flock, // works
&infinity, // works
&plasma, // works
- // &invadersSmall, // works ish
+ &invadersSmall, // works ish
// &invadersMedium, // fail
// &invadersLarge, // fail
&snake, // ok