Skip to content

Commit

Permalink
Add wheel2d (Seen at Burning Man), add Effects class, scale virtual 2D
Browse files Browse the repository at this point in the history
index.css: modal screen transparent black background

AppEffects: 
- SinelonEffect: add speed parameter
- RunningEffect: add 2 runs (temporary)
- RunningEffect: add speed and fade control
- Add Effects class (to have all effect functionality in one file)

AppLedsV:
- ledFixProjectAndMap: 2D to 2D: add scale factor in case virtual width and height is too high (wip)

AppModLedFixGen:
- add 2DWheel / wheel2D (BM)

AppModLeds
- use Effects class
  • Loading branch information
ewowi committed Sep 11, 2023
1 parent 068eb97 commit 0c98d44
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 426 deletions.
5 changes: 3 additions & 2 deletions data/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ h1,h2 {
right: 0px;
top: 0px;
/* calc(var(--th) - 1px); */
background: linear-gradient(to bottom, #ffbe3390 0%, #b60f6290 100%); /*var(--c-o);*/
/* background-color: linear-gradient(to bottom, #ffbe3399 0%, #b60f6299 100%); var(--c-o); */
background-color: var(--c-o);
transform: translateY(100%);
transition: transform 0.4s;
padding: 8px;
Expand Down Expand Up @@ -155,7 +156,7 @@ h1,h2 {
--c-l: #48a;
--c-y: #a90;
--t-b: 0.5;
--c-o: rgba(195, 145, 145, 0.9); /* used for modal background, changed to more readable*/
--c-o: rgba(34, 34, 34, 0.9);
--c-tb : rgba(34, 34, 34, var(--t-b));
--c-tba: rgba(102, 102, 102, var(--t-b));
--c-tbh: rgba(51, 51, 51, var(--t-b));
Expand Down
103 changes: 97 additions & 6 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ class SinelonEffect: public Effect {
Effect::loop();
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( ledsP, LedsV::nrOfLedsP, 20);
int pos = beatsin16( 13, 0, LedsV::nrOfLedsV-1 );
int pos = beatsin16( mdl->getValue("speed").as<int>(), 0, LedsV::nrOfLedsV-1 );
// ledsV[pos] += CHSV( gHue, 255, 192);
ledsV[pos] = ledsV.getPixelColor(pos) + CHSV( gHue, 255, 192);
// CRGB x = ledsV[pos];
}
bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 128, false);
return true;
}
};

//https://www.perfectcircuit.com/signal/difference-between-waveforms
class RunningEffect: public Effect {
public:
const char * name() {
Expand All @@ -95,11 +100,21 @@ class RunningEffect: public Effect {
void loop() {
Effect::loop();
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( ledsP, LedsV::nrOfLedsP, 70); //physical leds
fadeToBlackBy( ledsP, LedsV::nrOfLedsP, mdl->getValue("fade").as<int>()); //physical leds
// int pos0 = (call-1)%ledsV.nrOfLeds;
// leds[pos0] = CHSV( 0,0,0);
int pos = call%LedsV::nrOfLedsV; //Virtual leds
ledsV[pos] = CHSV( gHue, 255, 192); //make sore the right physical leds get their value
int pos = map(beat16( mdl->getValue("speed").as<int>()), 0, uint16_t(-1), 0, LedsV::nrOfLedsV-1 );
int pos2 = map(beat16( mdl->getValue("speed").as<int>(), 1000), 0, uint16_t(-1), 0, LedsV::nrOfLedsV-1 );
// int pos = call%LedsV::nrOfLedsV; //Virtual leds
ledsV[LedsV::nrOfLedsV -1 - pos] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
ledsV[LedsV::nrOfLedsV -1 - pos2] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
}
bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 128, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "comment", "in BPM!");
});
ui->initSlider(parentVar, "fade", 128, false);
return true;
}
};

Expand Down Expand Up @@ -639,7 +654,83 @@ class AudioRings:public RingEffect {
}
};


#endif // End Audio Effects

static std::vector<Effect *> effects;
class Effects {
public:
std::vector<Effect *> effects;

Effects() {
//create effects before fx.chFun is called
effects.push_back(new RainbowEffect);
effects.push_back(new RainbowWithGlitterEffect);
effects.push_back(new SinelonEffect);
effects.push_back(new RunningEffect);
effects.push_back(new ConfettiEffect);
effects.push_back(new BPMEffect);
effects.push_back(new JuggleEffect);
effects.push_back(new Ripples3DEffect);
effects.push_back(new SphereMove3DEffect);
effects.push_back(new Frizzles2D);
effects.push_back(new Lines2D);
effects.push_back(new DistortionWaves2D);
effects.push_back(new BouncingBalls1D);
effects.push_back(new RingRandomFlow);
#ifdef USERMOD_WLEDAUDIO
effects.push_back(new GEQEffect);
effects.push_back(new AudioRings);
#endif
}

size_t size() {
return effects.size();
}

bool setEffect(const char * id, size_t index) {
bool doMap = false;

print->print("setEffect %d %d %d \n", index, effects.size(), size());
if (index < size()) {

//tbd: make property of effects
if (strstr(effects[index]->name(), "2D")) {
if (LedsV::fxDimension != 2) {
LedsV::fxDimension = 2;
doMap = true;
}
}
else if (strstr(effects[index]->name(), "3D")) {
if (LedsV::fxDimension != 3) {
LedsV::fxDimension = 3;
doMap = true;
}
}
else {
if (LedsV::fxDimension != 1) {
LedsV::fxDimension = 1;
doMap = true;
}
}

JsonObject parentVar = mdl->findVar(id);
parentVar.remove("n"); //tbd: we should also remove the uiFun and chFun !!

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

print->printJson("parentVar", parentVar);
web->sendDataWs(parentVar); //always send, also when no children, to remove them from ui
} // fx < size

return doMap;

}

void loop(size_t index) {
// print->print("loop %d\n", index);

effects[index]->loop();
}

};
30 changes: 21 additions & 9 deletions src/App/AppLedsV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,41 @@ void LedsV::ledFixProjectAndMap() {
widthV = widthP;
heightV = heightP;
depthV = 1;
bucket = x + y * widthV;
float scale = 1;
if (widthV * heightV > 256)
scale = sqrt((float)256.0 / (widthV * heightV));
widthV *= scale;
heightV *= scale;
x = (x+1) * scale - 1;
y = (y+1) * scale - 1;
bucket = x + y * widthV;
// print->print("2D to 2D bucket %f %d %d x %d %d x %d\n", scale, bucket, x, y, widthV, heightV);
}
else if (ledFixDimension == 3) {//ledfix is 3D
widthV = widthP + heightP;
heightV = depthP;
depthV = 1;
bucket = (x + y + 1) + z * widthV;
bucket = (x + y + 1) + z * widthV;
// print->print("2D to 3D bucket %d %d\n", bucket, widthV);
}
}
//tbd: effect is 3D

if (bucket != -1) {
//add physical tables if not present
if (bucket >= mappingTable.size()) {
for (int i = mappingTable.size(); i<=bucket;i++) {
// print->print("mapping add physMap %d %d\n", bucket, mappingTable.size());
std::vector<uint16_t> physMap;
mappingTable.push_back(physMap);
if (bucket >= NUM_LEDS_Preview) {
print->print("mapping add physMap %d %d too big\n", bucket, mappingTable.size());
}
else {
if (bucket >= mappingTable.size()) {
for (int i = mappingTable.size(); i<=bucket;i++) {
// print->print("mapping add physMap %d %d\n", bucket, mappingTable.size());
std::vector<uint16_t> physMap;
mappingTable.push_back(physMap);
}
}
mappingTable[bucket].push_back(mappingTableLedCounter);
}

mappingTable[bucket].push_back(mappingTableLedCounter);
}
}

Expand Down
49 changes: 41 additions & 8 deletions src/App/AppModLedFixGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,36 @@ class GenFix {

void ring2D (uint16_t startX, uint16_t startY, uint16_t nrOfLeds) {

float size = nrOfLeds / M_PI;
// float size = nrOfLeds / 2 / M_PI;
openPin();

float ringDiam = 10 * nrOfLeds / 2 / M_PI; //in mm
for (int i=0; i<nrOfLeds; i++) {
float radians = i*360/nrOfLeds * (M_PI / 180);
uint16_t x = 10 * size / 2 + ringDiam * sinf(radians);
uint16_t y = 10 * size / 2 + ringDiam * cosf(radians);
uint16_t x = ringDiam + ringDiam * sinf(radians);
uint16_t y = ringDiam + ringDiam * cosf(radians);
write2D(x+startX,y+startY);
}
closePin();
}

void wheel2D (uint16_t startX, uint16_t startY, uint16_t nrOfSpokes, uint16_t ledsPerSpoke) {

float size = 50 + 10 * ledsPerSpoke;
openPin();

for (int i=0; i<nrOfSpokes; i++) {
float radians = i*360/nrOfSpokes * (M_PI / 180);
for (int j=0;j<ledsPerSpoke;j++) {
float ringDiam = 50 + 10 * j; //in mm
uint16_t x = size + ringDiam * sinf(radians);
uint16_t y = size + ringDiam * cosf(radians);
write2D(x+startX,y+startY);
}
}
closePin();
}

void rings241 (uint16_t startX, uint16_t startY) {
float ringDiam;
uint8_t ringsNrOfLeds[9] = {1, 8, 12, 16, 24, 32, 40, 48, 60};
Expand Down Expand Up @@ -370,11 +387,12 @@ class AppModLedFixGen:public Module {
select.add("2DRing"); //2
select.add("2DRings241"); //3
select.add("2DCloud"); //4
select.add("2DWall"); //8
select.add("3DCone"); //5
select.add("3DSideCube"); //6
select.add("3DCube"); //7
select.add("3DGlobe"); //8
select.add("2DWall"); //5
select.add("2DWheel"); //6
select.add("3DCone"); //7
select.add("3DSideCube"); //8
select.add("3DCube"); //9
select.add("3DGlobe"); //10
}, [](JsonObject var) { //chFun
ledFixGenChFun(var);
}); //ledFixGen
Expand Down Expand Up @@ -403,6 +421,7 @@ class AppModLedFixGen:public Module {
f_2DRings241,
f_2DCloud,
f_2DWall,
f_2DWheel,
f_3DCone,
f_3DSideCube,
f_3DCube,
Expand All @@ -425,6 +444,10 @@ class AppModLedFixGen:public Module {
else if (value == f_2DRings241) {
ui->initCheckBox(parentVar, "in2out", true, false);
}
else if (value == f_2DWheel) {
ui->initNumber(parentVar, "nrOfSpokes", 36, false);
ui->initNumber(parentVar, "ledsPerSpoke", 24, false);
}
else if (value == f_3DCone) {
ui->initCheckBox(parentVar, "in2out", true, false);
ui->initNumber(parentVar, "nrOfRings", 24, false);
Expand Down Expand Up @@ -529,6 +552,16 @@ class AppModLedFixGen:public Module {

// genFix.spiral1D(240, 0, 0, 48);

genFix.closeHeader();
}
else if (fix == f_2DWheel) {
uint16_t nrOfSpokes = mdl->getValue("nrOfSpokes");
uint16_t ledsPerSpoke = mdl->getValue("ledsPerSpoke");

genFix.openHeader("2DWheel%02d_%d", nrOfSpokes, ledsPerSpoke);

genFix.wheel2D(0, 0, nrOfSpokes, ledsPerSpoke);

genFix.closeHeader();

} else if (fix == f_3DCone) {
Expand Down
Loading

0 comments on commit 0c98d44

Please sign in to comment.