Skip to content

Commit

Permalink
Make AuroraDemo great again.
Browse files Browse the repository at this point in the history
And test out ChatGPT's attempt to create some effects as well.
  • Loading branch information
mrcodetastic committed Jul 29, 2024
1 parent e2f856d commit f77a5ca
Show file tree
Hide file tree
Showing 44 changed files with 788 additions and 1,217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "Vector.h"
#include "Vector2.hpp"

class Attractor {
public:
Expand All @@ -33,7 +33,7 @@ class Attractor {
PVector location; // Location

Attractor() {
location = PVector(VPANEL_W/2, VPANEL_H/2);
location = PVector(effects.getCenterX(), effects.getCenterY());
mass = 10;
G = .5;
}
Expand Down
91 changes: 58 additions & 33 deletions examples/AuroraDemo/AuroraDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
- "GFX_Lite" to provide a simple graphics library for drawing on the virtual display.
GFX_Lite is a fork of AdaFruitGFX and FastLED library combined together, with a focus on simplicity and ease of use.
Instructions:
* Use the serial input to advance through the patterns, or to toggle auto advance. Sending 'n' will advance to the next
pattern, 'p' will go to the previous pattern. Sending 'a' will toggle auto advance on and off.
*/

#define USE_GFX_LITE 1
Expand Down Expand Up @@ -59,21 +63,21 @@ MatrixPanel_I2S_DMA *matrix = nullptr;
// placeholder for the virtual display object
VirtualMatrixPanel *virtualDisp = nullptr;

// Aurora related
#include "Effects.h"
Effects effects(VPANEL_W, VPANEL_H);

#include "Drawable.h"
#include "Playlist.h"
#include "Geometry.h"
#include "EffectsLayer.hpp" // FastLED CRGB Pixel Buffer for which the patterns are drawn
EffectsLayer effects(VPANEL_W, VPANEL_H);

#include "Drawable.hpp"
#include "Geometry.hpp"

#include "Patterns.h"
#include "Patterns.hpp"
Patterns patterns;

/* -------------------------- Some variables -------------------------- */
unsigned long ms_current = 0;
unsigned long ms_previous = 0;
unsigned long ms_animation_max_duration = 10000; // 10 seconds
unsigned long ms_previous_palette = 0;
unsigned long ms_animation_max_duration = 30000; // 10 seconds
unsigned long next_frame = 0;

void listPatterns();
Expand Down Expand Up @@ -121,50 +125,71 @@ void setup()
Serial.println("VIRTUAL PANEL HEIGHT " + String(VPANEL_H));
#endif

// setup the effects generator
effects.Setup();

delay(500);
Serial.println("Effects being loaded: ");
listPatterns();

Serial.println("LastPattern index: " + String(lastPattern));

patterns.setPattern(lastPattern); // // simple noise
patterns.setPattern(0);
patterns.start();

ms_previous = millis();

Serial.print("Starting with pattern: ");
Serial.println(patterns.getCurrentPatternName());

}


void patternAdvance(){
// Go to next pattern in the list (se Patterns.h)
patterns.stop();
bool autoAdvance = true;
char incomingByte = 0;
void handleSerialRead()
{
if (Serial.available() > 0) {

patterns.moveRandom(1);
//patterns.move(1);
patterns.start();
// read the incoming byte:
incomingByte = Serial.read();

if (incomingByte == 'n') {
Serial.println("Going to next pattern");
patterns.move(1);
}

if (incomingByte == 'p') {
Serial.println("Going to previous pattern");
patterns.move(-1);
}

if (incomingByte == 'a') {
autoAdvance = !autoAdvance;

if (autoAdvance)
Serial.println("Auto pattern advance is ON");
else
Serial.println("Auto pattern advance is OFF");
}

ms_previous = millis();
}
} // end handleSerialRead

// Select a random palette as well
effects.RandomPalette();
Serial.print("Changing pattern to: ");
Serial.println(patterns.getCurrentPatternName());

}

void loop()
{


handleSerialRead();

ms_current = millis();
if ( (ms_current - ms_previous) > ms_animation_max_duration )

if (ms_current - ms_previous_palette > 10000) // change colour palette evert 10 seconds
{
patternAdvance();
effects.RandomPalette();
ms_previous_palette = ms_current;
}

if ( ((ms_current - ms_previous) > ms_animation_max_duration) && autoAdvance)
{

patterns.move(1);

// just auto-change the palette
effects.RandomPalette();
ms_previous = ms_current;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,5 @@ class Boid {
}
};

static const uint8_t AVAILABLE_BOID_COUNT = 40;
static const uint8_t AVAILABLE_BOID_COUNT = VPANEL_W;
Boid boids[AVAILABLE_BOID_COUNT];
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@



class Effects {
class EffectsLayer : public GFX {

public:

Expand All @@ -80,7 +80,7 @@ class Effects {
int height;
int num_leds = 0;

Effects(int w, int h) : width(w), height(h) {
EffectsLayer(int w, int h) : GFX(w, h), width(w), height(h) {

// we do dynamic allocation for leds buffer, otherwise esp32 toolchain can't link static arrays of such a big size for 256+ matrices
leds = (CRGB *)malloc((width * height + 1) * sizeof(CRGB));
Expand All @@ -93,10 +93,15 @@ class Effects {
noise[i] = (uint8_t *)malloc(height * sizeof(uint8_t));
}

// Set starting palette
currentPalette = RainbowColors_p;
loadPalette(0);
NoiseVariablesSetup();

ClearFrame();
}

~Effects(){
~EffectsLayer(){
free(leds);
for (int i = 0; i < width; ++i) {
free(noise[i]);
Expand Down Expand Up @@ -134,6 +139,15 @@ class Effects {
}
}

uint16_t getCenterX() {
return width / 2;
}

uint16_t getCenterY() {
return height / 2;
}


// scale the brightness of the screenbuffer down
void DimAll(byte value) {
for (int i = 0; i < num_leds; i++)
Expand Down Expand Up @@ -186,11 +200,6 @@ class Effects {
static const int HeatColorsPaletteIndex = 6;
static const int RandomPaletteIndex = 9;

void Setup() {
currentPalette = RainbowColors_p;
loadPalette(0);
NoiseVariablesSetup();
}

void CyclePalette(int offset = 1) {
loadPalette(paletteIndex + offset);
Expand Down Expand Up @@ -679,13 +688,6 @@ class Effects {
}
}

// write one pixel with the specified color from the current palette to coordinates
/*
void Pixel(int x, int y, uint8_t colorIndex) {
leds[XY16(x, y)] = ColorFromCurrentPalette(colorIndex);
matrix.drawBackgroundPixelRGB888(x,y, leds[XY16(x, y)]); // now draw it?
}
*/

CRGB ColorFromCurrentPalette(uint8_t index = 0, uint8_t brightness = 255, TBlendType blendType = LINEARBLEND) {
return ColorFromPalette(currentPalette, index, brightness, currentBlendType);
Expand Down Expand Up @@ -794,7 +796,22 @@ class Effects {
} // end column loop
} /// MoveY


// Override GFX methods
void drawPixel(int16_t x, int16_t y, uint16_t color) override {
setPixel(x, y, CRGB(color));
}

// Override GFX methods
void drawPixel(int16_t x, int16_t y, CRGB color) override {
setPixel(x, y, color);
}

void fillScreen(uint16_t color) override {
ClearFrame();
}

// Add any other GFX methods you want to override

};

#endif
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class PatternAttract : public Drawable {
private:
const int count = 8;
const int count = AVAILABLE_BOID_COUNT-1;
Attractor attractor;

public:
Expand All @@ -38,7 +38,7 @@ class PatternAttract : public Drawable {
direction = -1;

for (int i = 0; i < count; i++) {
Boid boid = Boid(15, 31 - i);
Boid boid = Boid(VPANEL_W/2, VPANEL_H - i);
boid.mass = 1; // random(0.1, 2);
boid.velocity.x = ((float) random(40, 50)) / 100.0;
boid.velocity.x *= direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class PatternBounce : public Drawable {
private:
static const int count = 32;
static const int count = VPANEL_W-1;
PVector gravity = PVector(0, 0.0125);

public:
Expand Down Expand Up @@ -56,7 +56,7 @@ class PatternBounce : public Drawable {

boid.update();

effects.drawBackgroundFastLEDPixelCRGB(boid.location.x, boid.location.y, effects.ColorFromCurrentPalette(boid.colorIndex));
effects.setPixel(boid.location.x, boid.location.y, effects.ColorFromCurrentPalette(boid.colorIndex));

if (boid.location.y >= VPANEL_H - 1) {
boid.location.y = VPANEL_H - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PatternCube : public Drawable {
int cubeWidth = 28; // Cube size
float Angx = 20.0, AngxSpeed = 0.05; // rotation (angle+speed) around X-axis
float Angy = 10.0, AngySpeed = 0.05; // rotation (angle+speed) around Y-axis
float Ox = 15.5, Oy = 15.5; // position (x,y) of the frame center
float Ox = VPANEL_W/2, Oy = VPANEL_H/2; // position (x,y) of the frame center
int zCamera = 110; // distance from cube to the eye of the camera

// Local vertices
Expand Down Expand Up @@ -151,11 +151,11 @@ class PatternCube : public Drawable {
public:
PatternCube() {
name = (char *)"Cube";
make(cubeWidth);
make(VPANEL_W);
}

unsigned int drawFrame() {
uint8_t blurAmount = beatsin8(2, 10, 255);
uint8_t blurAmount = beatsin8(2, 10, 128);

#if FASTLED_VERSION >= 3001000
blur2d(effects.leds, VPANEL_W, VPANEL_H, blurAmount);
Expand All @@ -164,8 +164,8 @@ class PatternCube : public Drawable {
#endif

zCamera = beatsin8(2, 100, 140);
AngxSpeed = beatsin8(3, 1, 10) / 100.0f;
AngySpeed = beatcos8(5, 1, 10) / 100.0f;
AngxSpeed = beatsin8(3, 1, 6) / 100.0f;
AngySpeed = effects.beatcos8(5, 1, 6) / 100.0f;

// Update values
Angx += AngxSpeed;
Expand All @@ -188,7 +188,7 @@ class PatternCube : public Drawable {
{
e = edge + i;
if (!e->visible) {
matrix.drawLine(screen[e->x].x, screen[e->x].y, screen[e->y].x, screen[e->y].y, color);
effects.drawLine(screen[e->x].x, screen[e->x].y, screen[e->y].x, screen[e->y].y, color);
}
}

Expand All @@ -200,7 +200,7 @@ class PatternCube : public Drawable {
e = edge + i;
if (e->visible)
{
matrix.drawLine(screen[e->x].x, screen[e->x].y, screen[e->y].x, screen[e->y].y, color);
effects.drawLine(screen[e->x].x, screen[e->x].y, screen[e->y].x, screen[e->y].y, color);
}
}

Expand Down
Loading

0 comments on commit f77a5ca

Please sign in to comment.