From de7a7a57b12f70d65302e40a8b696211c3d0a127 Mon Sep 17 00:00:00 2001 From: Brandon502 <105077712+Brandon502@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:10:50 -0400 Subject: [PATCH] Checkerboard & Spacing Projection --- src/App/LedLayer.h | 1 + src/App/LedModEffects.h | 1 + src/App/LedProjections.h | 92 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/src/App/LedLayer.h b/src/App/LedLayer.h index ce902a24..6aed2fec 100644 --- a/src/App/LedLayer.h +++ b/src/App/LedLayer.h @@ -48,6 +48,7 @@ enum ProjectionsE p_Kaleidoscope, p_Scrolling, p_Acceleration, + p_Checkerboard, p_count // keep as last entry }; diff --git a/src/App/LedModEffects.h b/src/App/LedModEffects.h index b6627223..41b2dee0 100644 --- a/src/App/LedModEffects.h +++ b/src/App/LedModEffects.h @@ -140,6 +140,7 @@ class LedModEffects:public SysModule { fixture.projections.push_back(new KaleidoscopeProjection); fixture.projections.push_back(new ScrollingProjection); fixture.projections.push_back(new AccelerationProjection); + fixture.projections.push_back(new CheckerboardProjection); #ifdef STARLIGHT_CLOCKLESS_LED_DRIVER #if !(CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2) diff --git a/src/App/LedProjections.h b/src/App/LedProjections.h index 6b64d5c8..6b9c9fd9 100644 --- a/src/App/LedProjections.h +++ b/src/App/LedProjections.h @@ -618,7 +618,38 @@ class SpacingProjection: public Projection { const char * name() {return "Spacing WIP";} const char * tags() {return "💡";} + void setup(LedsLayer &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted, Coord3D &mapped, uint16_t &indexV) { + adjustSizeAndPixel(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted); + DefaultProjection dp; + dp.setup(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted, mapped, indexV); + } + + void adjustSizeAndPixel(LedsLayer &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + // UI Variables + leds.projectionData.begin(); + Coord3D spacing = leds.projectionData.read(); + + // ppf ("pixel: %d,%d,%d -> ", pixelAdjusted.x, pixelAdjusted.y, pixelAdjusted.z); + spacing = spacing.maximum(Coord3D{0, 0, 0}) + Coord3D{1,1,1}; // {1, 1, 1} is the minimum value + + if (pixelAdjusted % spacing == Coord3D{0,0,0}) pixelAdjusted /= spacing; + else pixelAdjusted = Coord3D{UINT16_MAX, UINT16_MAX, UINT16_MAX}; + + // ppf ("%d,%d,%d\n", pixelAdjusted.x, pixelAdjusted.y, pixelAdjusted.z); + + sizeAdjusted = (sizeAdjusted + spacing - Coord3D{1,1,1}) / spacing; // round up + midPosAdjusted /= spacing; + } + void controls(LedsLayer &leds, JsonObject parentVar) { + leds.projectionData.reset(); + Coord3D *spacing = leds.projectionData.write({1,1,1}); + ui->initCoord3D(parentVar, "Spacing", spacing, 0, 100, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onChange: + leds.fixture->layers[rowNr]->triggerMapping(); + return true; + default: return false; + }}); } }; //SpacingProjection @@ -770,6 +801,67 @@ class AccelerationProjection: public Projection { } }; //Acceleration +class CheckerboardProjection: public Projection { + const char * name() {return "Checkerboard";} + const char * tags() {return "💫";} + + void setup(LedsLayer &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted, Coord3D &mapped, uint16_t &indexV) { + leds.projectionData.begin(); + Coord3D size = leds.projectionData.read(); + bool invert = leds.projectionData.read(); + bool group = leds.projectionData.read(); + adjustSizeAndPixel(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted); + if (group) {GroupingProjection gp; gp.setup(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted, mapped, indexV);} + else {DefaultProjection dp; dp.setup(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted, mapped, indexV);} + } + + void adjustSizeAndPixel(LedsLayer &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + // UI Variables + leds.projectionData.begin(); + Coord3D size = leds.projectionData.read(); + bool invert = leds.projectionData.read(); + + // ppf ("pixel: %d,%d,%d -> ", pixelAdjusted.x, pixelAdjusted.y, pixelAdjusted.z); + size = size.maximum(Coord3D{1, 1, 1}); // {1, 1, 1} is the minimum value + + Coord3D check = pixelAdjusted / size; + if ((check.x + check.y + check.z) % 2 == 0) { + if (invert) pixelAdjusted = {UINT16_MAX, UINT16_MAX, UINT16_MAX}; + } + else { + if (!invert) pixelAdjusted = {UINT16_MAX, UINT16_MAX, UINT16_MAX}; + } + + // ppf ("%d,%d,%d", pixelAdjusted.x, pixelAdjusted.y, pixelAdjusted.z); + // ppf (" Check: %d,%d,%d Even: %d\n", check.x, check.y, check.z, (check.x + check.y + check.z) % 2 == 0); + } + + void controls(LedsLayer &leds, JsonObject parentVar) { + leds.projectionData.reset(); + Coord3D *size = leds.projectionData.write({3,3,3}); + bool *invert = leds.projectionData.write(false); + bool *group = leds.projectionData.write(false); + ui->initCoord3D(parentVar, "Square Size", size, 0, 100, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onChange: + leds.fixture->layers[rowNr]->triggerMapping(); + return true; + default: return false; + }}); + ui->initCheckBox(parentVar, "Invert", invert, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onChange: + leds.fixture->layers[rowNr]->triggerMapping(); + return true; + default: return false; + }}); + ui->initCheckBox(parentVar, "Group", group, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onChange: + leds.fixture->layers[rowNr]->triggerMapping(); + return true; + default: return false; + }}); + } +}; //CheckerboardProjection + class TestProjection: public Projection { const char * name() {return "Test";} const char * tags() {return "💡";}