Skip to content

Commit

Permalink
Add DistortionWaves2D effect
Browse files Browse the repository at this point in the history
  • Loading branch information
ewowi committed Aug 10, 2023
1 parent ac09c02 commit b5db2e1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 51 deletions.
68 changes: 67 additions & 1 deletion src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class Frizzles2D: public Effect {
CRGB color = ColorFromPalette(palette, beatsin8(12, 0, 255), 255);
ledsV[x + y * LedsV::widthV] = color;
}
blur2d(ledsP, LedsV::widthV, LedsV::heightV, mdl->getValue("blur")); //this is tricky as FastLed is not aware of our virtual
blur2d(ledsP, LedsV::widthP, LedsV::heightP, mdl->getValue("blur")); //this is tricky as FastLed is not aware of our virtual
}
bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 128, false);
Expand Down Expand Up @@ -267,5 +267,71 @@ class Lines2D: public Effect {
}
}; // Lines2D

uint8_t gamma8(uint8_t b) { //we do nothing with gamma for now
return b;
}

class DistortionWaves2D: public Effect {
public:
const char * name() {
return "DistortionWaves 2D";
}

void setup() {
// fadeToBlackBy( ledsP, LedsV::nrOfLedsP, 100); //like more the gradual change
}

void loop() {

const uint16_t cols = LedsV::widthV;
const uint16_t rows = LedsV::widthV;

uint8_t speed = mdl->getValue("speed").as<int>()/32;
uint8_t scale = mdl->getValue("scale").as<int>()/32;

uint8_t w = 2;

uint16_t a = millis()/32;
uint16_t a2 = a/2;
uint16_t a3 = a/3;

uint16_t cx = beatsin8(10-speed,0,cols-1)*scale;
uint16_t cy = beatsin8(12-speed,0,rows-1)*scale;
uint16_t cx1 = beatsin8(13-speed,0,cols-1)*scale;
uint16_t cy1 = beatsin8(15-speed,0,rows-1)*scale;
uint16_t cx2 = beatsin8(17-speed,0,cols-1)*scale;
uint16_t cy2 = beatsin8(14-speed,0,rows-1)*scale;

uint16_t xoffs = 0;
for (int x = 0; x < cols; x++) {
xoffs += scale;
uint16_t yoffs = 0;

for (int y = 0; y < rows; y++) {
yoffs += scale;

byte rdistort = cos8((cos8(((x<<3)+a )&255)+cos8(((y<<3)-a2)&255)+a3 )&255)>>1;
byte gdistort = cos8((cos8(((x<<3)-a2)&255)+cos8(((y<<3)+a3)&255)+a+32 )&255)>>1;
byte bdistort = cos8((cos8(((x<<3)+a3)&255)+cos8(((y<<3)-a) &255)+a2+64)&255)>>1;

byte valueR = rdistort+ w* (a- ( ((xoffs - cx) * (xoffs - cx) + (yoffs - cy) * (yoffs - cy))>>7 ));
byte valueG = gdistort+ w* (a2-( ((xoffs - cx1) * (xoffs - cx1) + (yoffs - cy1) * (yoffs - cy1))>>7 ));
byte valueB = bdistort+ w* (a3-( ((xoffs - cx2) * (xoffs - cx2) + (yoffs - cy2) * (yoffs - cy2))>>7 ));

valueR = gamma8(cos8(valueR));
valueG = gamma8(cos8(valueG));
valueB = gamma8(cos8(valueB));

ledsV[x + y * LedsV::widthV] = CRGB(valueR, valueG, valueB);
}
}
}
bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 128, false);
ui->initSlider(parentVar, "scale", 128, false);
return true;
}
}; // Frizzles2D


static std::vector<Effect *> effects;
53 changes: 3 additions & 50 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,56 +90,8 @@ class AppModLeds:public Module {

Effect* effect = effects[fx];
effect->setup(); //if changed then run setup once (like call==0 in WLED)
if (!effect->controls(parentVar)) {

for (int i=0; i<5; i++) {
uint8_t nameNr = random8(6);
uint8_t typeNr = random8(5);
char name[12];
switch (nameNr) {
case 0:
strcpy(name, "lorum");
break;
case 1:
strcpy(name, "ipsum");
break;
case 2:
strcpy(name, "dolor");
break;
case 3:
strcpy(name, "sit");
break;
case 4:
strcpy(name, "amet");
break;
case 5:
strcpy(name, "consectetur");
break;
}

switch (typeNr) {
case 0:
ui->initText(parentVar, name, name, false);
break;
case 1:
ui->initNumber(parentVar, name, random8(255), false);
break;
case 2:
ui->initSlider(parentVar, name, random8(255), false);
break;
case 3:
ui->initCheckBox(parentVar, name, random8(2), false);
break;
case 4:
ui->initSelect(parentVar, name, random8(2), false, [](JsonObject var) { //uiFun
JsonArray select = web->addResponseA(var["id"], "select");
select.add("Oui"); //0
select.add("Non"); //1
});
break;
}
} //for loop
} //! controls
effect->controls(parentVar);

print->printJson("parentVar", parentVar);
web->sendDataWs(parentVar); //always send, also when no children, to remove them from ui
} // fx < size
Expand Down Expand Up @@ -250,6 +202,7 @@ class AppModLeds:public Module {
effects.push_back(new SphereMove3DEffect);
effects.push_back(new Frizzles2D);
effects.push_back(new Lines2D);
effects.push_back(new DistortionWaves2D);

// FastLED.addLeds<NEOPIXEL, 6>(leds, 1);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(ledsP, NUM_LEDS_FastLed);
Expand Down

0 comments on commit b5db2e1

Please sign in to comment.