This commit is contained in:
mrcodetastic 2024-07-28 23:40:30 +01:00
parent f2634319ab
commit 3960bbed88
25 changed files with 279 additions and 322 deletions

View file

@ -33,7 +33,7 @@ public:
PVector location; // Location PVector location; // Location
Attractor() { Attractor() {
location = PVector(MATRIX_CENTRE_X, MATRIX_CENTRE_Y); location = PVector(VPANEL_W/2, VPANEL_H/2);
mass = 10; mass = 10;
G = .5; G = .5;
} }

View file

@ -61,7 +61,7 @@ VirtualMatrixPanel *virtualDisp = nullptr;
// Aurora related // Aurora related
#include "Effects.h" #include "Effects.h"
Effects effects; Effects effects(VPANEL_W, VPANEL_H);
#include "Drawable.h" #include "Drawable.h"
#include "Playlist.h" #include "Playlist.h"
@ -73,7 +73,7 @@ Patterns patterns;
/* -------------------------- Some variables -------------------------- */ /* -------------------------- Some variables -------------------------- */
unsigned long ms_current = 0; unsigned long ms_current = 0;
unsigned long ms_previous = 0; unsigned long ms_previous = 0;
unsigned long ms_animation_max_duration = 20000; // 10 seconds unsigned long ms_animation_max_duration = 10000; // 10 seconds
unsigned long next_frame = 0; unsigned long next_frame = 0;
void listPatterns(); void listPatterns();

View file

@ -7,6 +7,8 @@
* Portions of this code are adapted from "NoiseSmearing" by Stefan Petrick: https://gist.github.com/StefanPetrick/9ee2f677dbff64e3ba7a * Portions of this code are adapted from "NoiseSmearing" by Stefan Petrick: https://gist.github.com/StefanPetrick/9ee2f677dbff64e3ba7a
* Copyright (c) 2014 Stefan Petrick * Copyright (c) 2014 Stefan Petrick
* http://www.stefan-petrick.de/wordpress_beta * http://www.stefan-petrick.de/wordpress_beta
*
* Modified by Codetastic 2024
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in * this software and associated documentation files (the "Software"), to deal in
@ -29,106 +31,74 @@
#ifndef Effects_H #ifndef Effects_H
#define Effects_H #define Effects_H
/* ---------------------------- GLOBAL CONSTANTS ----------------------------- */
const int MATRIX_CENTER_X = VPANEL_W / 2;
const int MATRIX_CENTER_Y = VPANEL_H / 2;
// US vs GB, huh? :)
//const byte MATRIX_CENTRE_X = MATRIX_CENTER_X - 1;
//const byte MATRIX_CENTRE_Y = MATRIX_CENTER_Y - 1;
#define MATRIX_CENTRE_X MATRIX_CENTER_X
#define MATRIX_CENTRE_Y MATRIX_CENTER_Y
const uint16_t NUM_LEDS = (VPANEL_W * VPANEL_H) + 1; // one led spare to capture out of bounds /**
* The one for 256+ matrices
* otherwise this:
* for (uint8_t i = 0; i < VPANEL_W; i++) {}
* turns into an infinite loop
*/
uint16_t XY16( uint16_t x, uint16_t y)
{
if( x >= VPANEL_W) return 0;
if( y >= VPANEL_H) return 0;
// forward declaration return (y * VPANEL_W) + x;
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: VPANEL_W-1 etc.
* Ugh... uint8_t - really??? this weak method can't cope with 256+ pixel matrices :(
*/
uint16_t XY( uint8_t x, uint8_t y)
{
return XY16(x, y);
}
/**
* The one for 256+ matrices
* otherwise this:
* for (uint8_t i = 0; i < VPANEL_W; i++) {}
* turns into an infinite loop
*/
uint16_t XY16( uint16_t x, uint16_t y)
{
if( x >= VPANEL_W) return 0;
if( y >= VPANEL_H) return 0;
return (y * VPANEL_W) + x + 1; // everything offset by one to compute out of bounds stuff - never displayed by ShowFrame()
}
uint8_t beatcos8(accum88 beats_per_minute, uint8_t lowest = 0, uint8_t highest = 255, uint32_t timebase = 0, uint8_t phase_offset = 0) /* 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
uint8_t beat = beat8(beats_per_minute, timebase); * (i.e. 64 pixels or 32 pixels.). Max value: VPANEL_W-1 etc.
uint8_t beatcos = cos8(beat + phase_offset); * Ugh... uint8_t - really??? this weak method can't cope with 256+ pixel matrices :(
uint8_t rangewidth = highest - lowest; */
uint8_t scaledbeat = scale8(beatcos, rangewidth); uint16_t XY( uint16_t x, uint16_t y)
uint8_t result = lowest + scaledbeat; {
return result; return XY16(x, y);
} }
uint8_t mapsin8(uint8_t theta, uint8_t lowest = 0, uint8_t highest = 255) {
uint8_t beatsin = sin8(theta);
uint8_t rangewidth = highest - lowest;
uint8_t scaledbeat = scale8(beatsin, rangewidth);
uint8_t result = lowest + scaledbeat;
return result;
}
uint8_t mapcos8(uint8_t theta, uint8_t lowest = 0, uint8_t highest = 255) {
uint8_t beatcos = cos8(theta);
uint8_t rangewidth = highest - lowest;
uint8_t scaledbeat = scale8(beatcos, rangewidth);
uint8_t result = lowest + scaledbeat;
return result;
}
// Array of temperature readings at each simulation cell
//byte heat[NUM_LEDS]; // none of the currently enabled effects uses this
uint32_t noise_x;
uint32_t noise_y;
uint32_t noise_z;
uint32_t noise_scale_x;
uint32_t noise_scale_y;
//uint8_t noise[VPANEL_W][VPANEL_H];
uint8_t **noise = nullptr; // we will allocate mem later
uint8_t noisesmoothing;
class Effects { class Effects {
public:
CRGB *leds;
Effects(){ public:
uint32_t noise_x;
uint32_t noise_y;
uint32_t noise_z;
uint32_t noise_scale_x;
uint32_t noise_scale_y;
uint8_t **noise = nullptr; // we will allocate mem later
uint8_t noisesmoothing;
CRGB *leds;
int width;
int height;
int num_leds = 0;
Effects(int w, int 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 // 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(NUM_LEDS * sizeof(CRGB)); leds = (CRGB *)malloc((width * height + 1) * sizeof(CRGB));
num_leds = width * height;
// allocate mem for noise effect // allocate mem for noise effect
// (there should be some guards for malloc errors eventually) // (there should be some guards for malloc errors eventually)
noise = (uint8_t **)malloc(VPANEL_W * sizeof(uint8_t *)); noise = (uint8_t **)malloc(width * sizeof(uint8_t *));
for (int i = 0; i < VPANEL_W; ++i) { for (int i = 0; i < width; ++i) {
noise[i] = (uint8_t *)malloc(VPANEL_H * sizeof(uint8_t)); noise[i] = (uint8_t *)malloc(height * sizeof(uint8_t));
} }
ClearFrame(); ClearFrame();
} }
~Effects(){ ~Effects(){
free(leds); free(leds);
for (int i = 0; i < VPANEL_W; ++i) { for (int i = 0; i < width; ++i) {
free(noise[i]); free(noise[i]);
} }
free(noise); free(noise);
@ -141,91 +111,69 @@ public:
* As such, any time these effects want to write a pixel color, we first have to update * As such, any time these effects want to write a pixel color, we first have to update
* the leds or leds2 array, and THEN write it to the RGB panel. This enables us to 'look up' the array to see what a pixel color was previously, each drawFrame(). * the leds or leds2 array, and THEN write it to the RGB panel. This enables us to 'look up' the array to see what a pixel color was previously, each drawFrame().
*/ */
void drawBackgroundFastLEDPixelCRGB(int16_t x, int16_t y, CRGB color) void setPixel(int16_t x, int16_t y, CRGB color)
{ {
leds[XY(x, y)] = color; leds[XY16(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 // write one pixel with the specified color from the current palette to coordinates
void Pixel(int x, int y, uint8_t colorIndex) { void setPixelFromPaletteIndex(int x, int y, uint8_t colorIndex) {
leds[XY(x, y)] = ColorFromCurrentPalette(colorIndex); leds[XY16(x, y)] = ColorFromCurrentPalette(colorIndex);
//matrix.drawPixelRGB888(x, y, temp.r, temp.g, temp.b); // now draw it?
} }
void PrepareFrame() { void PrepareFrame() { }
// leds = (CRGB*) backgroundLayer.backBuffer();
}
void ShowFrame() { void ShowFrame() { // send to display
//#if (FASTLED_VERSION >= 3001000)
// nblendPaletteTowardPalette(currentPalette, targetPalette, 24);
//#else
currentPalette = targetPalette; currentPalette = targetPalette;
//#endif
for (int y=0; y<height; ++y){
// backgroundLayer.swapBuffers(); for (int x=0; x<width; ++x){
// leds = (CRGB*) backgroundLayer.backBuffer(); uint16_t _pixel = XY16(x,y);
// LEDS.countFPS(); virtualDisp->drawPixelRGB888( x, y, leds[_pixel].r, leds[_pixel].g, leds[_pixel].b);
} // end loop to copy fast led to the dma matrix
for (int y=0; y<VPANEL_H; ++y){ }
for (int x=0; x<VPANEL_W; ++x){
//Serial.printf("Flushing x, y coord %d, %d\n", x, y);
uint16_t _pixel = XY16(x,y);
virtualDisp->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 // scale the brightness of the screenbuffer down
void DimAll(byte value) void DimAll(byte value) {
{ for (int i = 0; i < num_leds; i++)
for (int i = 0; i < NUM_LEDS; i++) leds[i].nscale8(value);
{
leds[i].nscale8(value);
}
} }
void ClearFrame() void ClearFrame() {
for (int i = 0; i < num_leds; i++)
leds[i]= CRGB(0,0,0);
}
uint8_t beatcos8(accum88 beats_per_minute, uint8_t lowest = 0, uint8_t highest = 255, uint32_t timebase = 0, uint8_t phase_offset = 0)
{ {
memset(leds, 0x00, NUM_LEDS * sizeof(CRGB)); // flush uint8_t beat = beat8(beats_per_minute, timebase);
uint8_t beatcos = cos8(beat + phase_offset);
uint8_t rangewidth = highest - lowest;
uint8_t scaledbeat = scale8(beatcos, rangewidth);
uint8_t result = lowest + scaledbeat;
return result;
} }
uint8_t mapsin8(uint8_t theta, uint8_t lowest = 0, uint8_t highest = 255) {
uint8_t beatsin = sin8(theta);
uint8_t rangewidth = highest - lowest;
uint8_t scaledbeat = scale8(beatsin, rangewidth);
uint8_t result = lowest + scaledbeat;
return result;
}
uint8_t mapcos8(uint8_t theta, uint8_t lowest = 0, uint8_t highest = 255) {
uint8_t beatcos = cos8(theta);
uint8_t rangewidth = highest - lowest;
uint8_t scaledbeat = scale8(beatcos, rangewidth);
uint8_t result = lowest + scaledbeat;
return result;
}
/*
void CircleStream(uint8_t value) {
DimAll(value); ShowFrame();
for (uint8_t offset = 0; offset < MATRIX_CENTER_X; offset++) {
boolean hasprev = false;
uint16_t prevxy = 0;
for (uint8_t theta = 0; theta < 255; theta++) {
uint8_t x = mapcos8(theta, offset, (VPANEL_W - 1) - offset);
uint8_t y = mapsin8(theta, offset, (VPANEL_H - 1) - offset);
uint16_t xy = XY(x, y);
if (hasprev) {
leds[prevxy] += leds[xy];
}
prevxy = xy;
hasprev = true;
}
}
for (uint8_t x = 0; x < VPANEL_W; x++) {
for (uint8_t y = 0; y < VPANEL_H; y++) {
uint16_t xy = XY(x, y);
leds[xy] = leds2[xy];
leds[xy].nscale8(value);
leds2[xy].nscale8(value);
}
}
}
*/
// palettes // palettes
static const int paletteCount = 10; static const int paletteCount = 10;
@ -394,7 +342,7 @@ public:
if (osci[4] % 2 == 0) if (osci[4] % 2 == 0)
osci[5] = osci[5] + 1; // .5 osci[5] = osci[5] + 1; // .5
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
p[i] = map8(sin8(osci[i]), 0, VPANEL_W - 1); //why? to keep the result in the range of 0-VPANEL_W (matrix size) p[i] = map8(sin8(osci[i]), 0, width - 1); //why? to keep the result in the range of 0-VPANEL_W (matrix size)
} }
} }
@ -404,11 +352,11 @@ public:
// rotates the first 16x16 quadrant 3 times onto a 32x32 (+90 degrees rotation for each one) // rotates the first 16x16 quadrant 3 times onto a 32x32 (+90 degrees rotation for each one)
void Caleidoscope1() { void Caleidoscope1() {
for (int x = 0; x < MATRIX_CENTER_X; x++) { for (int x = 0; x < width / 2; x++) {
for (int y = 0; y < MATRIX_CENTER_Y; y++) { for (int y = 0; y < height / 2; y++) {
leds[XY16(VPANEL_W - 1 - x, y)] = leds[XY16(x, y)]; leds[XY16(width - 1 - x, y)] = leds[XY16(x, y)];
leds[XY16(VPANEL_W - 1 - x, VPANEL_H - 1 - y)] = leds[XY16(x, y)]; leds[XY16(width - 1 - x, height - 1 - y)] = leds[XY16(x, y)];
leds[XY16(x, VPANEL_H - 1 - y)] = leds[XY16(x, y)]; leds[XY16(x, height - 1 - y)] = leds[XY16(x, y)];
} }
} }
} }
@ -416,19 +364,19 @@ public:
// mirror the first 16x16 quadrant 3 times onto a 32x32 // mirror the first 16x16 quadrant 3 times onto a 32x32
void Caleidoscope2() { void Caleidoscope2() {
for (int x = 0; x < MATRIX_CENTER_X; x++) { for (int x = 0; x < width / 2; x++) {
for (int y = 0; y < MATRIX_CENTER_Y; y++) { for (int y = 0; y < height / 2; y++) {
leds[XY16(VPANEL_W - 1 - x, y)] = leds[XY16(y, x)]; leds[XY16(width - 1 - x, y)] = leds[XY16(y, x)];
leds[XY16(x, VPANEL_H - 1 - y)] = leds[XY16(y, x)]; leds[XY16(x, height - 1 - y)] = leds[XY16(y, x)];
leds[XY16(VPANEL_W - 1 - x, VPANEL_H - 1 - y)] = leds[XY16(x, y)]; leds[XY16(width - 1 - x, height - 1 - y)] = leds[XY16(x, y)];
} }
} }
} }
// copy one diagonal triangle into the other one within a 16x16 // copy one diagonal triangle into the other one within a 16x16
void Caleidoscope3() { void Caleidoscope3() {
for (int x = 0; x <= MATRIX_CENTRE_X && x < VPANEL_H; x++) { for (int x = 0; x <= width / 2 - 1 && x < height; x++) {
for (int y = 0; y <= x && y<VPANEL_H; y++) { for (int y = 0; y <= x && y<height; y++) {
leds[XY16(x, y)] = leds[XY16(y, x)]; leds[XY16(x, y)] = leds[XY16(y, x)];
} }
} }
@ -436,48 +384,48 @@ public:
// copy one diagonal triangle into the other one within a 16x16 (90 degrees rotated compared to Caleidoscope3) // copy one diagonal triangle into the other one within a 16x16 (90 degrees rotated compared to Caleidoscope3)
void Caleidoscope4() { void Caleidoscope4() {
for (int x = 0; x <= MATRIX_CENTRE_X; x++) { for (int x = 0; x <= width / 2 - 1; x++) {
for (int y = 0; y <= MATRIX_CENTRE_Y - x; y++) { for (int y = 0; y <= height / 2 - 1 - x; y++) {
leds[XY16(MATRIX_CENTRE_Y - y, MATRIX_CENTRE_X - x)] = leds[XY16(x, y)]; leds[XY16(height / 2 - 1 - y, width / 2 - 1 - x)] = leds[XY16(x, y)];
} }
} }
} }
// copy one diagonal triangle into the other one within a 8x8 // copy one diagonal triangle into the other one within a 8x8
void Caleidoscope5() { void Caleidoscope5() {
for (int x = 0; x < VPANEL_W / 4; x++) { for (int x = 0; x < width / 4; x++) {
for (int y = 0; y <= x && y<=VPANEL_H; y++) { for (int y = 0; y <= x && y<=height; y++) {
leds[XY16(x, y)] = leds[XY16(y, x)]; leds[XY16(x, y)] = leds[XY16(y, x)];
} }
} }
for (int x = VPANEL_W / 4; x < VPANEL_W / 2; x++) { for (int x = width / 4; x < width / 2; x++) {
for (int y = VPANEL_H / 4; y >= 0; y--) { for (int y = height / 4; y >= 0; y--) {
leds[XY16(x, y)] = leds[XY16(y, x)]; leds[XY16(x, y)] = leds[XY16(y, x)];
} }
} }
} }
void Caleidoscope6() { void Caleidoscope6() {
for (int x = 1; x < MATRIX_CENTER_X; x++) { for (int x = 1; x < width / 2; x++) {
leds[XY16(7 - x, 7)] = leds[XY16(x, 0)]; leds[XY16(7 - x, 7)] = leds[XY16(x, 0)];
} //a } //a
for (int x = 2; x < MATRIX_CENTER_X; x++) { for (int x = 2; x < width / 2; x++) {
leds[XY16(7 - x, 6)] = leds[XY16(x, 1)]; leds[XY16(7 - x, 6)] = leds[XY16(x, 1)];
} //b } //b
for (int x = 3; x < MATRIX_CENTER_X; x++) { for (int x = 3; x < width / 2; x++) {
leds[XY16(7 - x, 5)] = leds[XY16(x, 2)]; leds[XY16(7 - x, 5)] = leds[XY16(x, 2)];
} //c } //c
for (int x = 4; x < MATRIX_CENTER_X; x++) { for (int x = 4; x < width / 2; x++) {
leds[XY16(7 - x, 4)] = leds[XY16(x, 3)]; leds[XY16(7 - x, 4)] = leds[XY16(x, 3)];
} //d } //d
for (int x = 5; x < MATRIX_CENTER_X; x++) { for (int x = 5; x < width / 2; x++) {
leds[XY16(7 - x, 3)] = leds[XY16(x, 4)]; leds[XY16(7 - x, 3)] = leds[XY16(x, 4)];
} //e } //e
for (int x = 6; x < MATRIX_CENTER_X; x++) { for (int x = 6; x < width / 2; x++) {
leds[XY16(7 - x, 2)] = leds[XY16(x, 5)]; leds[XY16(7 - x, 2)] = leds[XY16(x, 5)];
} //f } //f
for (int x = 7; x < MATRIX_CENTER_X; x++) { for (int x = 7; x < width / 2; x++) {
leds[XY16(7 - x, 1)] = leds[XY16(x, 6)]; leds[XY16(7 - x, 1)] = leds[XY16(x, 6)];
} //g } //g
} }
@ -566,7 +514,7 @@ public:
} }
// give it a linear tail to the right // give it a linear tail to the right
void StreamRight(byte scale, int fromX = 0, int toX = VPANEL_W, int fromY = 0, int toY = VPANEL_H) void StreamRight(byte scale, int fromX = 0, int toX = 0, int fromY = 0, int toY = 0)
{ {
for (int x = fromX + 1; x < toX; x++) { for (int x = fromX + 1; x < toX; x++) {
for (int y = fromY; y < toY; y++) { for (int y = fromY; y < toY; y++) {
@ -579,7 +527,7 @@ public:
} }
// give it a linear tail to the left // give it a linear tail to the left
void StreamLeft(byte scale, int fromX = VPANEL_W, int toX = 0, int fromY = 0, int toY = VPANEL_H) void StreamLeft(byte scale, int fromX = 0, int toX = 0, int fromY = 0, int toY = 0)
{ {
for (int x = toX; x < fromX; x++) { for (int x = toX; x < fromX; x++) {
for (int y = fromY; y < toY; y++) { for (int y = fromY; y < toY; y++) {
@ -594,66 +542,66 @@ public:
// give it a linear tail downwards // give it a linear tail downwards
void StreamDown(byte scale) void StreamDown(byte scale)
{ {
for (int x = 0; x < VPANEL_W; x++) { for (int x = 0; x < width; x++) {
for (int y = 1; y < VPANEL_H; y++) { for (int y = 1; y < height; y++) {
leds[XY16(x, y)] += leds[XY16(x, y - 1)]; leds[XY16(x, y)] += leds[XY16(x, y - 1)];
leds[XY16(x, y)].nscale8(scale); leds[XY16(x, y)].nscale8(scale);
} }
} }
for (int x = 0; x < VPANEL_W; x++) for (int x = 0; x < width; x++)
leds[XY16(x, 0)].nscale8(scale); leds[XY16(x, 0)].nscale8(scale);
} }
// give it a linear tail upwards // give it a linear tail upwards
void StreamUp(byte scale) void StreamUp(byte scale)
{ {
for (int x = 0; x < VPANEL_W; x++) { for (int x = 0; x < width; x++) {
for (int y = VPANEL_H - 2; y >= 0; y--) { for (int y = height - 2; y >= 0; y--) {
leds[XY16(x, y)] += leds[XY16(x, y + 1)]; leds[XY16(x, y)] += leds[XY16(x, y + 1)];
leds[XY16(x, y)].nscale8(scale); leds[XY16(x, y)].nscale8(scale);
} }
} }
for (int x = 0; x < VPANEL_W; x++) for (int x = 0; x < width; x++)
leds[XY16(x, VPANEL_H - 1)].nscale8(scale); leds[XY16(x, height - 1)].nscale8(scale);
} }
// give it a linear tail up and to the left // give it a linear tail up and to the left
void StreamUpAndLeft(byte scale) void StreamUpAndLeft(byte scale)
{ {
for (int x = 0; x < VPANEL_W - 1; x++) { for (int x = 0; x < width - 1; x++) {
for (int y = VPANEL_H - 2; y >= 0; y--) { for (int y = height - 2; y >= 0; y--) {
leds[XY16(x, y)] += leds[XY16(x + 1, y + 1)]; leds[XY16(x, y)] += leds[XY16(x + 1, y + 1)];
leds[XY16(x, y)].nscale8(scale); leds[XY16(x, y)].nscale8(scale);
} }
} }
for (int x = 0; x < VPANEL_W; x++) for (int x = 0; x < width; x++)
leds[XY16(x, VPANEL_H - 1)].nscale8(scale); leds[XY16(x, height - 1)].nscale8(scale);
for (int y = 0; y < VPANEL_H; y++) for (int y = 0; y < height; y++)
leds[XY16(VPANEL_W - 1, y)].nscale8(scale); leds[XY16(width - 1, y)].nscale8(scale);
} }
// give it a linear tail up and to the right // give it a linear tail up and to the right
void StreamUpAndRight(byte scale) void StreamUpAndRight(byte scale)
{ {
for (int x = 0; x < VPANEL_W - 1; x++) { for (int x = 0; x < width - 1; x++) {
for (int y = VPANEL_H - 2; y >= 0; y--) { for (int y = height - 2; y >= 0; y--) {
leds[XY16(x + 1, y)] += leds[XY16(x, y + 1)]; leds[XY16(x + 1, y)] += leds[XY16(x, y + 1)];
leds[XY16(x, y)].nscale8(scale); leds[XY16(x, y)].nscale8(scale);
} }
} }
// fade the bottom row // fade the bottom row
for (int x = 0; x < VPANEL_W; x++) for (int x = 0; x < width; x++)
leds[XY16(x, VPANEL_H - 1)].nscale8(scale); leds[XY16(x, height - 1)].nscale8(scale);
// fade the right column // fade the right column
for (int y = 0; y < VPANEL_H; y++) for (int y = 0; y < height; y++)
leds[XY16(VPANEL_W - 1, y)].nscale8(scale); leds[XY16(width - 1, y)].nscale8(scale);
} }
// just move everything one line down // just move everything one line down
void MoveDown() { void MoveDown() {
for (int y = VPANEL_H - 1; y > 0; y--) { for (int y = height - 1; y > 0; y--) {
for (int x = 0; x < VPANEL_W; x++) { for (int x = 0; x < width; x++) {
leds[XY16(x, y)] = leds[XY16(x, y - 1)]; leds[XY16(x, y)] = leds[XY16(x, y - 1)];
} }
} }
@ -662,7 +610,7 @@ public:
// just move everything one line down // just move everything one line down
void VerticalMoveFrom(int start, int end) { void VerticalMoveFrom(int start, int end) {
for (int y = end; y > start; y--) { for (int y = end; y > start; y--) {
for (int x = 0; x < VPANEL_W; x++) { for (int x = 0; x < width; x++) {
leds[XY16(x, y)] = leds[XY16(x, y - 1)]; leds[XY16(x, y)] = leds[XY16(x, y - 1)];
} }
} }
@ -680,18 +628,18 @@ public:
// rotate + copy triangle (MATRIX_CENTER_X*MATRIX_CENTER_X) // rotate + copy triangle (MATRIX_CENTER_X*MATRIX_CENTER_X)
void RotateTriangle() { void RotateTriangle() {
for (int x = 1; x < MATRIX_CENTER_X; x++) { for (int x = 1; x < width / 2; x++) {
for (int y = 0; y < x; y++) { for (int y = 0; y < x; y++) {
leds[XY16(x, 7 - y)] = leds[XY16(7 - x, y)]; leds[XY16(x, height / 2 - 1 - y)] = leds[XY16(width / 2 - 1 - x, y)];
} }
} }
} }
// mirror + copy triangle (MATRIX_CENTER_X*MATRIX_CENTER_X) // mirror + copy triangle (MATRIX_CENTER_X*MATRIX_CENTER_X)
void MirrorTriangle() { void MirrorTriangle() {
for (int x = 1; x < MATRIX_CENTER_X; x++) { for (int x = 1; x < width / 2; x++) {
for (int y = 0; y < x; y++) { for (int y = 0; y < x; y++) {
leds[XY16(7 - y, x)] = leds[XY16(7 - x, y)]; leds[XY16(height / 2 - 1 - y, x)] = leds[XY16(width / 2 - 1 - x, y)];
} }
} }
} }
@ -699,9 +647,9 @@ public:
// draw static rainbow triangle pattern (MATRIX_CENTER_XxWIDTH / 2) // draw static rainbow triangle pattern (MATRIX_CENTER_XxWIDTH / 2)
// (just for debugging) // (just for debugging)
void RainbowTriangle() { void RainbowTriangle() {
for (int i = 0; i < MATRIX_CENTER_X; i++) { for (int i = 0; i < width / 2; i++) {
for (int j = 0; j <= i; j++) { for (int j = 0; j <= i; j++) {
Pixel(7 - i, j, i * j * 4); setPixelFromPaletteIndex(height / 2 - 1 - i, j, i * j * 4);
} }
} }
} }
@ -734,8 +682,8 @@ public:
// write one pixel with the specified color from the current palette to coordinates // write one pixel with the specified color from the current palette to coordinates
/* /*
void Pixel(int x, int y, uint8_t colorIndex) { void Pixel(int x, int y, uint8_t colorIndex) {
leds[XY(x, y)] = ColorFromCurrentPalette(colorIndex); leds[XY16(x, y)] = ColorFromCurrentPalette(colorIndex);
matrix.drawBackgroundPixelRGB888(x,y, leds[XY(x, y)]); // now draw it? matrix.drawBackgroundPixelRGB888(x,y, leds[XY16(x, y)]); // now draw it?
} }
*/ */
@ -761,11 +709,11 @@ public:
} }
void FillNoise() { void FillNoise() {
for (uint16_t i = 0; i < VPANEL_W; i++) { for (uint16_t i = 0; i < width; i++) {
uint32_t ioffset = noise_scale_x * (i - MATRIX_CENTRE_Y); uint32_t ioffset = noise_scale_x * (i - width / 2);
for (uint16_t j = 0; j < VPANEL_H; j++) { for (uint16_t j = 0; j < height; j++) {
uint32_t joffset = noise_scale_y * (j - MATRIX_CENTRE_Y); uint32_t joffset = noise_scale_y * (j - height / 2);
byte data = inoise16(noise_x + ioffset, noise_y + joffset, noise_z) >> 8; byte data = inoise16(noise_x + ioffset, noise_y + joffset, noise_z) >> 8;
@ -784,7 +732,7 @@ public:
CRGB tmp = 0; CRGB tmp = 0;
for (int y = 0; y < VPANEL_H; y++) for (int y = 0; y < height; y++)
{ {
// Shift Left: https://codedost.com/c/arraypointers-in-c/c-program-shift-elements-array-left-direction/ // Shift Left: https://codedost.com/c/arraypointers-in-c/c-program-shift-elements-array-left-direction/
@ -794,24 +742,24 @@ public:
for (int m = 0; m < delta; m++) for (int m = 0; m < delta; m++)
{ {
// Do this delta time for each row... computationally expensive potentially. // Do this delta time for each row... computationally expensive potentially.
for(int x = 0; x < VPANEL_W; x++) for(int x = 0; x < width; x++)
{ {
leds[XY16(x, y)] = leds [XY16(x+1, y)]; leds[XY16(x, y)] = leds [XY16(x+1, y)];
} }
leds[XY16(VPANEL_W-1, y)] = tmp; leds[XY16(width-1, y)] = tmp;
} }
/* /*
// Shift // Shift
for (int x = 0; x < VPANEL_W - delta; x++) { for (int x = 0; x < VPANEL_W - delta; x++) {
leds2[XY(x, y)] = leds[XY(x + delta, y)]; leds2[XY16(x, y)] = leds[XY16(x + delta, y)];
} }
// Wrap around // Wrap around
for (int x = VPANEL_W - delta; x < VPANEL_W; x++) { for (int x = VPANEL_W - delta; x < VPANEL_W; x++) {
leds2[XY(x, y)] = leds[XY(x + delta - VPANEL_W, y)]; leds2[XY16(x, y)] = leds[XY16(x + delta - VPANEL_W, y)];
} }
*/ */
} // end row loop } // end row loop
@ -820,7 +768,7 @@ public:
// write back to leds // write back to leds
for (uint8_t y = 0; y < VPANEL_H; y++) { for (uint8_t y = 0; y < VPANEL_H; y++) {
for (uint8_t x = 0; x < VPANEL_W; x++) { for (uint8_t x = 0; x < VPANEL_W; x++) {
leds[XY(x, y)] = leds2[XY(x, y)]; leds[XY16(x, y)] = leds2[XY16(x, y)];
} }
} }
*/ */
@ -830,18 +778,18 @@ public:
{ {
CRGB tmp = 0; CRGB tmp = 0;
for (int x = 0; x < VPANEL_W; x++) for (int x = 0; x < width; x++)
{ {
tmp = leds[XY16(x, 0)]; tmp = leds[XY16(x, 0)];
for (int m = 0; m < delta; m++) // moves for (int m = 0; m < delta; m++) // moves
{ {
// Do this delta time for each row... computationally expensive potentially. // Do this delta time for each row... computationally expensive potentially.
for(int y = 0; y < VPANEL_H; y++) for(int y = 0; y < height; y++)
{ {
leds[XY16(x, y)] = leds [XY16(x, y+1)]; leds[XY16(x, y)] = leds [XY16(x, y+1)];
} }
leds[XY16(x, VPANEL_H-1)] = tmp; leds[XY16(x, height-1)] = tmp;
} }
} // end column loop } // end column loop
} /// MoveY } /// MoveY

View file

@ -61,7 +61,7 @@ public:
boid.applyForce(force); boid.applyForce(force);
boid.update(); 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));
boids[i] = boid; boids[i] = boid;
} }

View file

@ -39,6 +39,9 @@ class PatternElectricMandala : public Drawable {
int16_t dsx; int16_t dsx;
int16_t dsy; int16_t dsy;
unsigned int last_parameter_change_ms = 0;
public: public:
PatternElectricMandala() { PatternElectricMandala() {
name = (char *)"ElectricMandala"; name = (char *)"ElectricMandala";
@ -46,18 +49,18 @@ class PatternElectricMandala : public Drawable {
void start() { void start() {
// set to reasonable values to avoid a black out // set to reasonable values to avoid a black out
noisesmoothing = 200; effects.noisesmoothing = 200;
// just any free input pin // just any free input pin
//random16_add_entropy(analogRead(18)); //random16_add_entropy(analogRead(18));
// fill coordinates with random values // fill coordinates with random values
// set zoom levels // set zoom levels
noise_x = random16(); effects.noise_x = random16();
noise_y = random16(); effects.noise_y = random16();
noise_z = random16(); effects.noise_z = random16();
noise_scale_x = 6000; effects.noise_scale_x = 6000;
noise_scale_y = 6000; effects.noise_scale_y = 6000;
// for the random movement // for the random movement
dx = random8(); dx = random8();
@ -70,19 +73,20 @@ class PatternElectricMandala : public Drawable {
unsigned int drawFrame() { unsigned int drawFrame() {
#if FASTLED_VERSION >= 3001000 #if FASTLED_VERSION >= 3001000
// a new parameter set every 15 seconds // a new parameter set every 15 seconds
EVERY_N_SECONDS(15) { if(millis() - last_parameter_change_ms > 15000) {
last_parameter_change_ms = millis();
//SetupRandomPalette3(); //SetupRandomPalette3();
dy = random16(500) - 250; // random16(2000) - 1000 is pretty fast but works fine, too dy = random16(500) - 250; // random16(2000) - 1000 is pretty fast but works fine, too
dx = random16(500) - 250; dx = random16(500) - 250;
dz = random16(500) - 250; dz = random16(500) - 250;
noise_scale_x = random16(10000) + 2000; effects.noise_scale_x = random16(10000) + 2000;
noise_scale_y = random16(10000) + 2000; effects.noise_scale_y = random16(10000) + 2000;
} }
#endif #endif
noise_y += dy; effects.noise_y += dy;
noise_x += dx; effects.noise_x += dx;
noise_z += dz; effects.noise_z += dz;
effects.FillNoise(); effects.FillNoise();
ShowNoiseLayer(0, 1, 0); ShowNoiseLayer(0, 1, 0);
@ -100,7 +104,7 @@ class PatternElectricMandala : public Drawable {
for (uint16_t i = 0; i < VPANEL_W; i++) { for (uint16_t i = 0; i < VPANEL_W; i++) {
for (uint16_t j = 0; j < VPANEL_H; j++) { for (uint16_t j = 0; j < VPANEL_H; j++) {
uint8_t color = noise[i][j]; uint8_t color = effects.noise[i][j];
uint8_t bri = color; uint8_t bri = color;

View file

@ -61,26 +61,26 @@ class PatternFire : public Drawable {
for (int x = 0; x < VPANEL_W; x++) { for (int x = 0; x < VPANEL_W; x++) {
// Step 1. Cool down every cell a little // Step 1. Cool down every cell a little
for (int y = 0; y < VPANEL_H; y++) { for (int y = 0; y < VPANEL_H; y++) {
int xy = XY(x, y); int xy = XY16(x, y);
heat[xy] = qsub8(heat[xy], random8(0, ((cooling * 10) / VPANEL_H) + 2)); heat[xy] = qsub8(heat[xy], random8(0, ((cooling * 10) / VPANEL_H) + 2));
} }
// Step 2. Heat from each cell drifts 'up' and diffuses a little // Step 2. Heat from each cell drifts 'up' and diffuses a little
for (int y = 0; y < VPANEL_H; y++) { for (int y = 0; y < VPANEL_H; y++) {
heat[XY(x, y)] = (heat[XY(x, y + 1)] + heat[XY(x, y + 2)] + heat[XY(x, y + 2)]) / 3; heat[XY16(x, y)] = (heat[XY16(x, y + 1)] + heat[XY16(x, y + 2)] + heat[XY16(x, y + 2)]) / 3;
} }
// Step 2. Randomly ignite new 'sparks' of heat // Step 2. Randomly ignite new 'sparks' of heat
if (random8() < sparking) { if (random8() < sparking) {
// int x = (p[0] + p[1] + p[2]) / 3; // int x = (p[0] + p[1] + p[2]) / 3;
int xy = XY(x, VPANEL_H - 1); int xy = XY16(x, VPANEL_H - 1);
heat[xy] = qadd8(heat[xy], random8(160, 255)); heat[xy] = qadd8(heat[xy], random8(160, 255));
} }
// Step 4. Map from heat cells to LED colors // Step 4. Map from heat cells to LED colors
for (int y = 0; y < VPANEL_H; y++) { for (int y = 0; y < VPANEL_H; y++) {
int xy = XY(x, y); int xy = XY16(x, y);
byte colorIndex = heat[xy]; byte colorIndex = heat[xy];
// Recommend that you use values 0-240 rather than // Recommend that you use values 0-240 rather than

View file

@ -95,8 +95,8 @@ class PatternFlock : public Drawable {
PVector location = boid->location; PVector location = boid->location;
// PVector velocity = boid->velocity; // PVector velocity = boid->velocity;
// backgroundLayer.drawLine(location.x, location.y, location.x - velocity.x, location.y - velocity.y, color); // backgroundLayer.drawLine(location.x, location.y, location.x - velocity.x, location.y - velocity.y, color);
// effects.leds[XY(location.x, location.y)] += color; // effects.leds[XY16(location.x, location.y)] += color;
effects.drawBackgroundFastLEDPixelCRGB(location.x, location.y, color); effects.setPixel(location.x, location.y, color);
if (applyWind) { if (applyWind) {
boid->applyForce(wind); boid->applyForce(wind);
@ -111,8 +111,8 @@ class PatternFlock : public Drawable {
PVector location = predator.location; PVector location = predator.location;
// PVector velocity = predator.velocity; // PVector velocity = predator.velocity;
// backgroundLayer.drawLine(location.x, location.y, location.x - velocity.x, location.y - velocity.y, color); // backgroundLayer.drawLine(location.x, location.y, location.x - velocity.x, location.y - velocity.y, color);
// effects.leds[XY(location.x, location.y)] += color; // effects.leds[XY16(location.x, location.y)] += color;
effects.drawBackgroundFastLEDPixelCRGB(location.x, location.y, color); effects.setPixel(location.x, location.y, color);
} }
if (millis() - last_update_hue_ms > 200) { if (millis() - last_update_hue_ms > 200) {

View file

@ -67,7 +67,7 @@ class PatternFlowField : public Drawable {
boid->velocity.y = -((float)cos8(angle) * 0.0078125 - 1.0); boid->velocity.y = -((float)cos8(angle) * 0.0078125 - 1.0);
boid->update(); boid->update();
effects.drawBackgroundFastLEDPixelCRGB(boid->location.x, boid->location.y, effects.ColorFromCurrentPalette(angle + hue)); // color effects.setPixel(boid->location.x, boid->location.y, effects.ColorFromCurrentPalette(angle + hue)); // color
if (boid->location.x < 0 || boid->location.x >= VPANEL_W || if (boid->location.x < 0 || boid->location.x >= VPANEL_W ||
boid->location.y < 0 || boid->location.y >= VPANEL_H) { boid->location.y < 0 || boid->location.y >= VPANEL_H) {

View file

@ -38,10 +38,10 @@ class PatternIncrementalDrift : public Drawable {
{ {
CRGB color = effects.ColorFromCurrentPalette((i - 2) * (240 / (VPANEL_W / 2))); CRGB color = effects.ColorFromCurrentPalette((i - 2) * (240 / (VPANEL_W / 2)));
uint8_t x = beatcos8((17 - i) * 2, MATRIX_CENTER_X - i, MATRIX_CENTER_X + i); uint8_t x = effects.beatcos8((17 - i) * 2, VPANEL_W/2 - i, VPANEL_W/2 + i);
uint8_t y = beatsin8((17 - i) * 2, MATRIX_CENTER_Y - i, MATRIX_CENTER_Y + i); uint8_t y = beatsin8((17 - i) * 2, VPANEL_H/2 - i, VPANEL_H/2 + i);
effects.drawBackgroundFastLEDPixelCRGB(x, y, color); effects.setPixel(x, y, color);
} }
return 0; return 0;

View file

@ -43,18 +43,18 @@ class PatternIncrementalDrift2 : public Drawable {
uint8_t y = 0; uint8_t y = 0;
if (i < 16) { if (i < 16) {
x = beatcos8((i + 1) * 2, i, VPANEL_W - i); x = effects.beatcos8((i + 1) * 2, i, VPANEL_W - i);
y = beatsin8((i + 1) * 2, i, VPANEL_H - i); y = beatsin8((i + 1) * 2, i, VPANEL_H - i);
color = effects.ColorFromCurrentPalette(i * 14); color = effects.ColorFromCurrentPalette(i * 14);
} }
else else
{ {
x = beatsin8((32 - i) * 2, VPANEL_W - i, i + 1); x = beatsin8((32 - i) * 2, VPANEL_W - i, i + 1);
y = beatcos8((32 - i) * 2, VPANEL_H - i, i + 1); y = effects.beatcos8((32 - i) * 2, VPANEL_H - i, i + 1);
color = effects.ColorFromCurrentPalette((31 - i) * 14); color = effects.ColorFromCurrentPalette((31 - i) * 14);
} }
effects.drawBackgroundFastLEDPixelCRGB(x, y, color); effects.setPixel(x, y, color);
} }
return 0; return 0;

View file

@ -51,7 +51,7 @@ public:
byte hue = sin8(effects.osci[5]); byte hue = sin8(effects.osci[5]);
// draw a pixel at x,y using a color from the current palette // draw a pixel at x,y using a color from the current palette
effects.Pixel(x, y, hue); effects.setPixelFromPaletteIndex(x, y, hue);
effects.ShowFrame(); effects.ShowFrame();
return 30; return 30;

View file

@ -48,10 +48,10 @@ class PatternInvadersSmall : public Drawable {
if (random(0, 2) == 1) color = color1; if (random(0, 2) == 1) color = color1;
effects.drawBackgroundFastLEDPixelCRGB(x + i, y + j, color); effects.setPixel(x + i, y + j, color);
if (i < 2) if (i < 2)
effects.drawBackgroundFastLEDPixelCRGB(x + (4 - i), y + j, color); effects.setPixel(x + (4 - i), y + j, color);
} }
} }
@ -92,10 +92,10 @@ class PatternInvadersMedium : public Drawable {
if (random(0, 2) == 1) color = color1; if (random(0, 2) == 1) color = color1;
effects.drawBackgroundFastLEDPixelCRGB(x + (i * 2), y + (j * 2), color); effects.setPixel(x + (i * 2), y + (j * 2), color);
if (i < 2) if (i < 2)
effects.drawBackgroundFastLEDPixelCRGB(x + (8 - i * 2), y + (j * 2), color); effects.setPixel(x + (8 - i * 2), y + (j * 2), color);
} }
} }
@ -138,10 +138,10 @@ class PatternInvadersLarge : public Drawable {
color = color1; color = color1;
} }
effects.drawBackgroundFastLEDPixelCRGB(1 + x * 6, 1 + y * 6, color); effects.setPixel(1 + x * 6, 1 + y * 6, color);
if (x < 2) if (x < 2)
effects.drawBackgroundFastLEDPixelCRGB(1 + (4 - x) * 6, 1 + y * 6, color); effects.setPixel(1 + (4 - x) * 6, 1 + y * 6, color);
} }
} }

View file

@ -85,7 +85,7 @@ public:
// Display current generation // Display current generation
for (int i = 0; i < VPANEL_W; i++) { for (int i = 0; i < VPANEL_W; i++) {
for (int j = 0; j < VPANEL_H; j++) { for (int j = 0; j < VPANEL_H; j++) {
effects.leds[XY(i, j)] = effects.ColorFromCurrentPalette(world[i][j].hue * 4, world[i][j].brightness); effects.leds[XY16(i, j)] = effects.ColorFromCurrentPalette(world[i][j].hue * 4, world[i][j].brightness);
} }
} }

View file

@ -175,7 +175,7 @@ private:
Point imagePoint = createPoint(point.x * 2, point.y * 2); Point imagePoint = createPoint(point.x * 2, point.y * 2);
//effects.drawBackgroundFastLEDPixelCRGB(imagePoint.x, imagePoint.y, CRGB(CRGB::Gray)); //effects.setPixel(imagePoint.x, imagePoint.y, CRGB(CRGB::Gray));
shuffleDirections(); shuffleDirections();
@ -191,7 +191,7 @@ private:
Point newImagePoint = imagePoint.Move(direction); Point newImagePoint = imagePoint.Move(direction);
effects.drawBackgroundFastLEDPixelCRGB(newImagePoint.x, newImagePoint.y, color); effects.setPixel(newImagePoint.x, newImagePoint.y, color);
cellCount++; cellCount++;
cells[cellCount - 1] = newPoint; cells[cellCount - 1] = newPoint;
@ -204,7 +204,7 @@ private:
if (index > -1) { if (index > -1) {
Point finishedPoint = cells[index]; Point finishedPoint = cells[index];
imagePoint = createPoint(finishedPoint.x * 2, finishedPoint.y * 2); imagePoint = createPoint(finishedPoint.x * 2, finishedPoint.y * 2);
effects.drawBackgroundFastLEDPixelCRGB(imagePoint.x, imagePoint.y, color); effects.setPixel(imagePoint.x, imagePoint.y, color);
removeCell(index); removeCell(index);
} }

View file

@ -45,7 +45,7 @@ public:
effects.leds[XY16(x, y)] = (x ^ y ^ flip) < count ? effects.ColorFromCurrentPalette(((x ^ y) << 2) + generation) : CRGB::Black; effects.leds[XY16(x, y)] = (x ^ y ^ flip) < count ? effects.ColorFromCurrentPalette(((x ^ y) << 2) + generation) : CRGB::Black;
// The below is more pleasant // The below is more pleasant
// effects.leds[XY(x, y)] = effects.ColorFromCurrentPalette(((x ^ y) << 2) + generation) ; // effects.leds[XY16(x, y)] = effects.ColorFromCurrentPalette(((x ^ y) << 2) + generation) ;
} }
} }

View file

@ -54,8 +54,8 @@ public:
byte x2 = 8 + sin8(counter * 2) / 16; byte x2 = 8 + sin8(counter * 2) / 16;
byte y2 = 8 + cos8((counter * 2) / 3) / 16; byte y2 = 8 + cos8((counter * 2) / 3) / 16;
effects.leds[XY(x1, x2)] = effects.ColorFromCurrentPalette(patternNoiseSmearingHue); effects.leds[XY16(x1, x2)] = effects.ColorFromCurrentPalette(patternNoiseSmearingHue);
effects.leds[XY(x2, y2)] = effects.ColorFromCurrentPalette(patternNoiseSmearingHue + 128); effects.leds[XY16(x2, y2)] = effects.ColorFromCurrentPalette(patternNoiseSmearingHue + 128);
// Noise // Noise
noise_x += 1000; noise_x += 1000;
@ -87,13 +87,13 @@ public:
byte xx = 4 + sin8(millis() / 9) / 10; byte xx = 4 + sin8(millis() / 9) / 10;
byte yy = 4 + cos8(millis() / 10) / 10; byte yy = 4 + cos8(millis() / 10) / 10;
effects.leds[XY(xx, yy)] += effects.ColorFromCurrentPalette(patternNoiseSmearingHue); effects.leds[XY16(xx, yy)] += effects.ColorFromCurrentPalette(patternNoiseSmearingHue);
xx = 8 + sin8(millis() / 10) / 16; xx = 8 + sin8(millis() / 10) / 16;
yy = 8 + cos8(millis() / 7) / 16; yy = 8 + cos8(millis() / 7) / 16;
effects.leds[XY(xx, yy)] += effects.ColorFromCurrentPalette(patternNoiseSmearingHue + 80); effects.leds[XY16(xx, yy)] += effects.ColorFromCurrentPalette(patternNoiseSmearingHue + 80);
effects.leds[XY(15, 15)] += effects.ColorFromCurrentPalette(patternNoiseSmearingHue + 160); effects.leds[XY16(15, 15)] += effects.ColorFromCurrentPalette(patternNoiseSmearingHue + 160);
noise_x += 1000; noise_x += 1000;
noise_y += 1000; noise_y += 1000;
@ -125,7 +125,7 @@ public:
effects.DimAll(235); effects.ShowFrame(); effects.DimAll(235); effects.ShowFrame();
for (uint8_t i = 3; i < 32; i = i + 4) { for (uint8_t i = 3; i < 32; i = i + 4) {
effects.leds[XY(i, 15)] += effects.ColorFromCurrentPalette(i * 8); effects.leds[XY16(i, 15)] += effects.ColorFromCurrentPalette(i * 8);
} }
// Noise // Noise
@ -159,7 +159,7 @@ public:
//CLS(); //CLS();
effects.DimAll(235); effects.ShowFrame(); effects.DimAll(235); effects.ShowFrame();
effects.leds[XY(15, 15)] += effects.ColorFromCurrentPalette(patternNoiseSmearingHue); effects.leds[XY16(15, 15)] += effects.ColorFromCurrentPalette(patternNoiseSmearingHue);
// Noise // Noise
@ -194,7 +194,7 @@ public:
for (uint8_t i = 3; i < 32; i = i + 4) { for (uint8_t i = 3; i < 32; i = i + 4) {
effects.leds[XY(i, 31)] += effects.ColorFromCurrentPalette(i * 8); effects.leds[XY16(i, 31)] += effects.ColorFromCurrentPalette(i * 8);
} }
// Noise // Noise
@ -228,7 +228,7 @@ public:
for (uint8_t y = 1; y < 32; y = y + 6) { for (uint8_t y = 1; y < 32; y = y + 6) {
for (uint8_t x = 1; x < 32; x = x + 6) { for (uint8_t x = 1; x < 32; x = x + 6) {
effects.leds[XY(x, y)] += effects.ColorFromCurrentPalette((x * y) / 4); effects.leds[XY16(x, y)] += effects.ColorFromCurrentPalette((x * y) / 4);
} }
} }
@ -263,7 +263,7 @@ public:
// draw a rainbow color palette // draw a rainbow color palette
for (uint8_t y = 0; y < VPANEL_H; y++) { for (uint8_t y = 0; y < VPANEL_H; y++) {
for (uint8_t x = 0; x < VPANEL_W; x++) { for (uint8_t x = 0; x < VPANEL_W; x++) {
effects.leds[XY(x, y)] += effects.ColorFromCurrentPalette(x * 8, y * 8 + 7); effects.leds[XY16(x, y)] += effects.ColorFromCurrentPalette(x * 8, y * 8 + 7);
} }
} }
@ -310,7 +310,7 @@ public:
for (uint8_t c = 0; c < 6; c++) { for (uint8_t c = 0; c < 6; c++) {
for (uint8_t j = 0; j < 5; j++) { for (uint8_t j = 0; j < 5; j++) {
for (uint8_t x = 0; x < VPANEL_W; x++) { for (uint8_t x = 0; x < VPANEL_W; x++) {
effects.leds[XY(x, y)] += rainbow[c]; effects.leds[XY16(x, y)] += rainbow[c];
} }
y++; y++;

View file

@ -56,7 +56,7 @@ class PatternPendulumWave : public Drawable {
uint8_t y = beatsin16(WAVE_BPM, 0, amp, x*beatsin16(SKEW_BPM, WAVE_TIMEMINSKEW, WAVE_TIMEMAXSKEW)) + offset; 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)); effects.setPixel(x, y, effects.ColorFromCurrentPalette(x * 7));
} }
effects.ShowFrame(); effects.ShowFrame();
return 20; return 20;

View file

@ -45,7 +45,7 @@ public:
v += cos16(y * (128 - wibble) * 6 + time); v += cos16(y * (128 - wibble) * 6 + time);
v += sin16(y * x * cos8(-time) / 8); v += sin16(y * x * cos8(-time) / 8);
effects.Pixel(x, y, (v >> 8) + 127); effects.setPixelFromPaletteIndex(x, y, (v >> 8) + 127);
} }
} }

View file

@ -36,12 +36,12 @@ class PatternRadar : public Drawable {
unsigned int drawFrame() { unsigned int drawFrame() {
effects.DimAll(254); effects.ShowFrame(); effects.DimAll(254); effects.ShowFrame();
for (int offset = 0; offset < MATRIX_CENTER_X; offset++) { for (int offset = 0; offset < VPANEL_W/2; offset++) {
byte hue = 255 - (offset * 16 + hueoffset); byte hue = 255 - (offset * 16 + hueoffset);
CRGB color = effects.ColorFromCurrentPalette(hue); CRGB color = effects.ColorFromCurrentPalette(hue);
uint8_t x = mapcos8(theta, offset, (VPANEL_W - 1) - offset); uint8_t x = effects.mapcos8(theta, offset, (VPANEL_W - 1) - offset);
uint8_t y = mapsin8(theta, offset, (VPANEL_H - 1) - offset); uint8_t y = effects.mapsin8(theta, offset, (VPANEL_H - 1) - offset);
uint16_t xy = XY(x, y); uint16_t xy = XY16(x, y);
effects.leds[xy] = color; effects.leds[xy] = color;
if (millis() - last_update_hue_ms > 25) { if (millis() - last_update_hue_ms > 25) {

View file

@ -27,6 +27,10 @@
#define PatternSimplexNoise_H #define PatternSimplexNoise_H
class PatternSimplexNoise : public Drawable { class PatternSimplexNoise : public Drawable {
private:
unsigned int last_update_ms = 0;
public: public:
PatternSimplexNoise() { PatternSimplexNoise() {
name = (char *)"Noise"; name = (char *)"Noise";
@ -34,18 +38,19 @@ class PatternSimplexNoise : public Drawable {
void start() { void start() {
// Initialize our coordinates to some random values // Initialize our coordinates to some random values
noise_x = random16(); effects.noise_x = random16();
noise_y = random16(); effects.noise_y = random16();
noise_z = random16(); effects.noise_z = random16();
} }
unsigned int drawFrame() { unsigned int drawFrame() {
#if FASTLED_VERSION >= 3001000 #if FASTLED_VERSION >= 3001000
// a new parameter set every 15 seconds // a new parameter set every 15 seconds
EVERY_N_SECONDS(15) { if(millis() - last_update_ms > 15000) {
noise_x = random16(); last_update_ms = millis();
noise_y = random16(); effects.noise_x = random16();
noise_z = random16(); effects.noise_y = random16();
effects.noise_z = random16();
} }
#endif #endif
@ -55,8 +60,8 @@ class PatternSimplexNoise : public Drawable {
ShowNoiseLayer(0, 1, 0); ShowNoiseLayer(0, 1, 0);
// noise_x += speed; // noise_x += speed;
noise_y += speed; effects.noise_y += speed;
noise_z += speed; effects.noise_z += speed;
effects.ShowFrame(); effects.ShowFrame();
@ -67,7 +72,7 @@ class PatternSimplexNoise : public Drawable {
void ShowNoiseLayer(byte layer, byte colorrepeat, byte colorshift) { void ShowNoiseLayer(byte layer, byte colorrepeat, byte colorshift) {
for (uint16_t i = 0; i < VPANEL_W; i++) { for (uint16_t i = 0; i < VPANEL_W; i++) {
for (uint16_t j = 0; j < VPANEL_H; j++) { for (uint16_t j = 0; j < VPANEL_H; j++) {
uint8_t pixel = noise[i][j]; uint8_t pixel = effects.noise[i][j];
// assign a color depending on the actual palette // assign a color depending on the actual palette
effects.leds[XY16(i, j)] = effects.ColorFromCurrentPalette(colorrepeat * (pixel + colorshift), pixel); effects.leds[XY16(i, j)] = effects.ColorFromCurrentPalette(colorrepeat * (pixel + colorshift), pixel);

View file

@ -96,7 +96,7 @@ private:
void draw(CRGB colors[SNAKE_LENGTH]) { void draw(CRGB colors[SNAKE_LENGTH]) {
for (byte i = 0; i < SNAKE_LENGTH; i++) { for (byte i = 0; i < SNAKE_LENGTH; i++) {
effects.leds[XY(pixels[i].x, pixels[i].y)] = colors[i] %= (255 - i * (255 / SNAKE_LENGTH)); effects.leds[XY16(pixels[i].x, pixels[i].y)] = colors[i] %= (255 - i * (255 / SNAKE_LENGTH));
} }
} }
}; };

View file

@ -57,26 +57,26 @@ class PatternSpark : public Drawable {
for (uint8_t x = 0; x < VPANEL_W; x++) { for (uint8_t x = 0; x < VPANEL_W; x++) {
// Step 1. Cool down every cell a little // Step 1. Cool down every cell a little
for (int y = 0; y < VPANEL_H; y++) { for (int y = 0; y < VPANEL_H; y++) {
int xy = XY(x, y); int xy = XY16(x, y);
heat[xy] = qsub8(heat[xy], random8(0, ((cooling * 10) / VPANEL_H) + 2)); heat[xy] = qsub8(heat[xy], random8(0, ((cooling * 10) / VPANEL_H) + 2));
} }
// Step 2. Heat from each cell drifts 'up' and diffuses a little // Step 2. Heat from each cell drifts 'up' and diffuses a little
for (int y = 0; y < VPANEL_H; y++) { for (int y = 0; y < VPANEL_H; y++) {
heat[XY(x, y)] = (heat[XY(x, y + 1)] + heat[XY(x, y + 2)] + heat[XY(x, y + 2)]) / 3; heat[XY16(x, y)] = (heat[XY16(x, y + 1)] + heat[XY16(x, y + 2)] + heat[XY16(x, y + 2)]) / 3;
} }
// Step 2. Randomly ignite new 'sparks' of heat // Step 2. Randomly ignite new 'sparks' of heat
if (random8() < sparking) { if (random8() < sparking) {
uint8_t xt = random8(MATRIX_CENTRE_X - 2, MATRIX_CENTER_X + 3); uint8_t xt = random8(MATRIX_CENTRE_X - 2, MATRIX_CENTER_X + 3);
int xy = XY(xt, VPANEL_H - 1); int xy = XY16(xt, VPANEL_H - 1);
heat[xy] = qadd8(heat[xy], random8(160, 255)); heat[xy] = qadd8(heat[xy], random8(160, 255));
} }
// Step 4. Map from heat cells to LED colors // Step 4. Map from heat cells to LED colors
for (int y = 0; y < VPANEL_H; y++) { for (int y = 0; y < VPANEL_H; y++) {
int xy = XY(x, y); int xy = XY16(x, y);
byte colorIndex = heat[xy]; byte colorIndex = heat[xy];
// Recommend that you use values 0-240 rather than // Recommend that you use values 0-240 rather than

View file

@ -30,12 +30,12 @@ class PatternSpiro : public Drawable {
uint8_t radiusx = VPANEL_W / 4; uint8_t radiusx = VPANEL_W / 4;
uint8_t radiusy = VPANEL_H / 4; uint8_t radiusy = VPANEL_H / 4;
uint8_t minx = MATRIX_CENTER_X - radiusx; uint8_t minx = VPANEL_W/2 - radiusx;
uint8_t maxx = MATRIX_CENTER_X + radiusx + 1; uint8_t maxx = VPANEL_W/2 + radiusx + 1;
uint8_t miny = MATRIX_CENTER_Y - radiusy; uint8_t miny = VPANEL_H/2 - radiusy;
uint8_t maxy = MATRIX_CENTER_Y + radiusy + 1; uint8_t maxy = VPANEL_H/2 + radiusy + 1;
uint8_t spirocount = 1; uint8_t spirocount = 16;
uint8_t spirooffset = 256 / spirocount; uint8_t spirooffset = 256 / spirocount;
boolean spiroincrement = true; boolean spiroincrement = true;
@ -60,17 +60,17 @@ class PatternSpiro : public Drawable {
boolean change = false; boolean change = false;
for (int i = 0; i < spirocount; i++) { for (int i = 0; i < spirocount; i++) {
uint8_t x = mapsin8(theta1 + i * spirooffset, minx, maxx); uint8_t x = effects.mapsin8(theta1 + i * spirooffset, minx, maxx);
uint8_t y = mapcos8(theta1 + i * spirooffset, miny, maxy); uint8_t y = effects.mapcos8(theta1 + i * spirooffset, miny, maxy);
uint8_t x2 = mapsin8(theta2 + i * spirooffset, x - radiusx, x + radiusx); uint8_t x2 = effects.mapsin8(theta2 + i * spirooffset, x - radiusx, x + radiusx);
uint8_t y2 = mapcos8(theta2 + i * spirooffset, y - radiusy, y + radiusy); uint8_t y2 = effects.mapcos8(theta2 + i * spirooffset, y - radiusy, y + radiusy);
CRGB color = effects.ColorFromCurrentPalette(hueoffset + i * spirooffset, 128); CRGB color = effects.ColorFromCurrentPalette(hueoffset + i * spirooffset, 128);
effects.leds[XY(x2, y2)] += color; effects.leds[XY16(x2, y2)] += color;
if((x2 == MATRIX_CENTER_X && y2 == MATRIX_CENTER_Y) || if((x2 == VPANEL_W/2 && y2 == VPANEL_H/2) ||
(x2 == MATRIX_CENTRE_X && y2 == MATRIX_CENTRE_Y)) change = true; (x2 == VPANEL_W/2 && y2 == VPANEL_H/2)) change = true;
} }
theta2 += 1; theta2 += 1;

View file

@ -62,12 +62,12 @@ class PatternSwirl : public Drawable {
// The color of each point shifts over time, each at a different speed. // The color of each point shifts over time, each at a different speed.
uint16_t ms = millis(); uint16_t ms = millis();
effects.leds[XY(i, j)] += effects.ColorFromCurrentPalette(ms / 11); effects.leds[XY16(i, j)] += effects.ColorFromCurrentPalette(ms / 11);
//effects.leds[XY(j, i)] += effects.ColorFromCurrentPalette(ms / 13); // this doesn't work for non-square matrices //effects.leds[XY16(j, i)] += effects.ColorFromCurrentPalette(ms / 13); // this doesn't work for non-square matrices
effects.leds[XY(ni, nj)] += effects.ColorFromCurrentPalette(ms / 17); effects.leds[XY16(ni, nj)] += effects.ColorFromCurrentPalette(ms / 17);
//effects.leds[XY(nj, ni)] += effects.ColorFromCurrentPalette(ms / 29); // this doesn't work for non-square matrices //effects.leds[XY16(nj, ni)] += effects.ColorFromCurrentPalette(ms / 29); // this doesn't work for non-square matrices
effects.leds[XY(i, nj)] += effects.ColorFromCurrentPalette(ms / 37); effects.leds[XY16(i, nj)] += effects.ColorFromCurrentPalette(ms / 37);
effects.leds[XY(ni, j)] += effects.ColorFromCurrentPalette(ms / 41); effects.leds[XY16(ni, j)] += effects.ColorFromCurrentPalette(ms / 41);
effects.ShowFrame(); effects.ShowFrame();

View file

@ -60,36 +60,36 @@ public:
case 0: case 0:
for (int x = 0; x < VPANEL_W; x++) { for (int x = 0; x < VPANEL_W; x++) {
n = quadwave8(x * 2 + theta) / scale; n = quadwave8(x * 2 + theta) / scale;
effects.drawBackgroundFastLEDPixelCRGB(x, n, effects.ColorFromCurrentPalette(x + hue)); effects.setPixel(x, n, effects.ColorFromCurrentPalette(x + hue));
if (waveCount == 2) if (waveCount == 2)
effects.drawBackgroundFastLEDPixelCRGB(x, maxY - n, effects.ColorFromCurrentPalette(x + hue)); effects.setPixel(x, maxY - n, effects.ColorFromCurrentPalette(x + hue));
} }
break; break;
case 1: case 1:
for (int y = 0; y < VPANEL_H; y++) { for (int y = 0; y < VPANEL_H; y++) {
n = quadwave8(y * 2 + theta) / scale; n = quadwave8(y * 2 + theta) / scale;
effects.drawBackgroundFastLEDPixelCRGB(n, y, effects.ColorFromCurrentPalette(y + hue)); effects.setPixel(n, y, effects.ColorFromCurrentPalette(y + hue));
if (waveCount == 2) if (waveCount == 2)
effects.drawBackgroundFastLEDPixelCRGB(maxX - n, y, effects.ColorFromCurrentPalette(y + hue)); effects.setPixel(maxX - n, y, effects.ColorFromCurrentPalette(y + hue));
} }
break; break;
case 2: case 2:
for (int x = 0; x < VPANEL_W; x++) { for (int x = 0; x < VPANEL_W; x++) {
n = quadwave8(x * 2 - theta) / scale; n = quadwave8(x * 2 - theta) / scale;
effects.drawBackgroundFastLEDPixelCRGB(x, n, effects.ColorFromCurrentPalette(x + hue)); effects.setPixel(x, n, effects.ColorFromCurrentPalette(x + hue));
if (waveCount == 2) if (waveCount == 2)
effects.drawBackgroundFastLEDPixelCRGB(x, maxY - n, effects.ColorFromCurrentPalette(x + hue)); effects.setPixel(x, maxY - n, effects.ColorFromCurrentPalette(x + hue));
} }
break; break;
case 3: case 3:
for (int y = 0; y < VPANEL_H; y++) { for (int y = 0; y < VPANEL_H; y++) {
n = quadwave8(y * 2 - theta) / scale; n = quadwave8(y * 2 - theta) / scale;
effects.drawBackgroundFastLEDPixelCRGB(n, y, effects.ColorFromCurrentPalette(y + hue)); effects.setPixel(n, y, effects.ColorFromCurrentPalette(y + hue));
if (waveCount == 2) if (waveCount == 2)
effects.drawBackgroundFastLEDPixelCRGB(maxX - n, y, effects.ColorFromCurrentPalette(y + hue)); effects.setPixel(maxX - n, y, effects.ColorFromCurrentPalette(y + hue));
} }
break; break;
} }