Skip to content

Commit

Permalink
add Noise2D and swap Pan and Tilt
Browse files Browse the repository at this point in the history
LedEffects: add Noise2D

LedLeds, LedModEffects, LedModFixture(Gen)
- swap Pan and Tilt (Tilt is on x-axis first)

LedModFixtureGen
- remove enum Fixtures
- add Strips group
- prepare for 1D,2D,3D icon (WIP)
  • Loading branch information
ewoudwijma committed May 9, 2024
1 parent 1c4cb3b commit 20f196d
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 140 deletions.
28 changes: 27 additions & 1 deletion src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,32 @@ class ScrollingText: public Effect {
default: return false;
}});
}
};
}; //ScrollingText

class Noise2D: public Effect {
const char * name() {return "Noise2D";}
unsigned8 dim() {return _2D;}
const char * tags() {return "💡";}

void loop(Leds &leds) {
CRGBPalette16 pal = getPalette();
stackUnsigned8 speed = mdl->getValue("speed");
stackUnsigned8 scale = mdl->getValue("scale");

for (int y = 0; y < leds.size.y; y++) {
for (int x = 0; x < leds.size.x; x++) {
uint8_t pixelHue8 = inoise8(x * scale, y * scale, now / (16 - speed));
leds.setPixelColor(leds.XY(x, y), ColorFromPalette(pal, pixelHue8));
}
}
}

void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "speed", 8, 0, 15);
ui->initSlider(parentVar, "scale", 128, 2, 255);
}
}; //Noise2D


#ifdef STARLEDS_USERMOD_WLEDAUDIO
Expand Down Expand Up @@ -1594,6 +1619,7 @@ class Effects {
effects.push_back(new Lissajous);
effects.push_back(new Frizzles);
effects.push_back(new ScrollingText);
effects.push_back(new Noise2D);
#ifdef STARLEDS_USERMOD_WLEDAUDIO
//2D WLED
effects.push_back(new Waverly);
Expand Down
8 changes: 4 additions & 4 deletions src/App/LedLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ void fastled_fill_rainbow(struct CRGB * targetArray, int numToFill, unsigned8 in
}

unsigned16 Leds::XYZ(unsigned16 x, unsigned16 y, unsigned16 z) {
if (projectionNr == p_PanTiltRoll || projectionNr == p_Preset1) {
if (projectionNr == p_TiltPanRoll || projectionNr == p_Preset1) {
Coord3D result = Coord3D{x, y, z};
if (proPanSpeed) result = trigoPanTiltRoll.pan(result, size/2, millis() * 5 / (255 - proPanSpeed));
if (proTiltSpeed) result = trigoPanTiltRoll.tilt(result, size/2, millis() * 5 / (255 - proTiltSpeed));
if (proRollSpeed) result = trigoPanTiltRoll.roll(result, size/2, millis() * 5 / (255 - proRollSpeed));
if (proTiltSpeed) result = trigoTiltPanRoll.tilt(result, size/2, millis() * 5 / (255 - proTiltSpeed));
if (proPanSpeed) result = trigoTiltPanRoll.pan(result, size/2, millis() * 5 / (255 - proPanSpeed));
if (proRollSpeed) result = trigoTiltPanRoll.roll(result, size/2, millis() * 5 / (255 - proRollSpeed));
if (fixture->fixSize.z == 1) result.z = 0; // 3d effects will be flattened on 2D fixtures
if (result >= 0 && result < size)
return result.x + result.y * size.x + result.z * size.x * size.y;
Expand Down
14 changes: 7 additions & 7 deletions src/App/LedLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum Projections
{
p_Default,
p_Multiply,
p_PanTiltRoll,
p_TiltPanRoll,
p_DistanceFromPoint,
p_Preset1,
p_None,
Expand All @@ -55,8 +55,8 @@ static unsigned trigoUnCached = 1;
struct Trigo {
uint16_t period = 360; //default period 360
Trigo(uint16_t period = 360) {this->period = period;}
float sinValue[3]; uint16_t sinAngle[3] = {UINT16_MAX,UINT16_MAX,UINT16_MAX}; //caching of sinValue=sin(sinAngle) for pan, tilt and roll
float cosValue[3]; uint16_t cosAngle[3] = {UINT16_MAX,UINT16_MAX,UINT16_MAX}; //caching of cosValue=cos(cosAngle) for pan, tilt and roll
float sinValue[3]; uint16_t sinAngle[3] = {UINT16_MAX,UINT16_MAX,UINT16_MAX}; //caching of sinValue=sin(sinAngle) for tilt, pan and roll
float cosValue[3]; uint16_t cosAngle[3] = {UINT16_MAX,UINT16_MAX,UINT16_MAX}; //caching of cosValue=cos(cosAngle) for tilt, pan and roll
virtual float sinBase(uint16_t angle) {return sinf(M_TWOPI * angle / period);}
virtual float cosBase(uint16_t angle) {return cosf(M_TWOPI * angle / period);}
int16_t sin(int16_t factor, uint16_t angle, uint8_t cache012 = 0) {
Expand Down Expand Up @@ -92,9 +92,9 @@ struct Trigo {
out.z = inM.z;
return out + middle;
}
Coord3D rotate(Coord3D in, Coord3D middle, uint16_t panAngle, uint16_t tiltAngle, uint16_t rollAngle, uint16_t period = 360) {
Coord3D rotate(Coord3D in, Coord3D middle, uint16_t tiltAngle, uint16_t panAngle, uint16_t rollAngle, uint16_t period = 360) {
this->period = period;
return roll(tilt(pan(in, middle, panAngle), middle, tiltAngle), middle, rollAngle);
return roll(pan(tilt(in, middle, tiltAngle), middle, panAngle), middle, rollAngle);
}
};

Expand All @@ -109,7 +109,7 @@ struct Trigo16: Trigo { //FastLed sin16 and cos16
float cosBase(uint16_t angle) {return cos16(65536.0f * angle / period) / 32645.0f;}
};

static Trigo trigoPanTiltRoll(255); // Trigo8 is hardly any faster (27 vs 28 fps) (spanXY=28)
static Trigo trigoTiltPanRoll(255); // Trigo8 is hardly any faster (27 vs 28 fps) (spanXY=28)

class Fixture; //forward

Expand Down Expand Up @@ -185,8 +185,8 @@ class Leds {
unsigned8 effectDimension = -1;

Coord3D startPos = {0,0,0}, endPos = {UINT16_MAX,UINT16_MAX,UINT16_MAX}; //default
unsigned8 proPanSpeed = 128;
unsigned8 proTiltSpeed = 128;
unsigned8 proPanSpeed = 128;
unsigned8 proRollSpeed = 128;

SharedData sharedData;
Expand Down
16 changes: 8 additions & 8 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class LedModEffects:public SysModule {
JsonArray options = ui->setOptions(var); // see enum Projections in LedFixture.h and keep the same order !
options.add("Default");
options.add("Multiply");
options.add("PanTiltRoll");
options.add("TiltPanRoll");
options.add("Distance ⌛");
options.add("Preset 1");
options.add("None");
Expand Down Expand Up @@ -181,23 +181,23 @@ class LedModEffects:public SysModule {
default: return false;
}});
}
if (proValue == p_PanTiltRoll || proValue == p_Preset1) {
ui->initSlider(var, "proPan", 128, 0, 254, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
if (proValue == p_TiltPanRoll || proValue == p_Preset1) {
ui->initSlider(var, "proTilt", 128, 0, 254, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ChangeFun:
if (rowNr < fixture.projections.size())
fixture.projections[rowNr]->proPanSpeed = mdl->getValue(var, rowNr);
fixture.projections[rowNr]->proTiltSpeed = mdl->getValue(var, rowNr);
return true;
default: return false;
}});
ui->initSlider(var, "proTilt", 128, 0, 254, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
ui->initSlider(var, "proPan", 128, 0, 254, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ChangeFun:
if (rowNr < fixture.projections.size())
fixture.projections[rowNr]->proTiltSpeed = mdl->getValue(var, rowNr);
fixture.projections[rowNr]->proPanSpeed = mdl->getValue(var, rowNr);
return true;
default: return false;
}});
}
if (proValue == p_Preset1 || proValue == p_PanTiltRoll) {
if (proValue == p_Preset1 || proValue == p_TiltPanRoll) {
ui->initSlider(var, "proRoll", 128, 0, 254, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Roll speed");
Expand Down Expand Up @@ -357,7 +357,7 @@ class LedModEffects:public SysModule {
mdl->getValueRowNr = rowNr++;
effects.loop(*leds);
mdl->getValueRowNr = UINT8_MAX;
if (leds->projectionNr == p_PanTiltRoll || leds->projectionNr == p_Preset1)
if (leds->projectionNr == p_TiltPanRoll || leds->projectionNr == p_Preset1)
leds->fadeToBlackBy(50);
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ class LedModFixture:public SysModule {
buffer[1] = 0;
buffer[2] = 0;
buffer[3] = 0;
} else if (viewRotation == 1) { //pan
buffer[1] = 0;//beatsin8(4, 250, 5); //tilt
buffer[2] = beat8(1);//, 0, 255); //pan
buffer[3] = 0;//beatsin8(6, 255, 5); //roll
} else if (viewRotation == 2) { //tilt
buffer[1] = beat8(1);//, 0, 255); //pan
buffer[2] = 0;//beatsin8(4, 250, 5); //tilt
buffer[3] = 0;//beatsin8(6, 255, 5); //roll
} else if (viewRotation == 1) { //tilt
buffer[1] = beat8(1);//, 0, 255);
buffer[2] = 0;//beatsin8(4, 250, 5);
buffer[3] = 0;//beatsin8(6, 255, 5);
} else if (viewRotation == 2) { //pan
buffer[1] = 0;//beatsin8(4, 250, 5);
buffer[2] = beat8(1);//, 0, 255);
buffer[3] = 0;//beatsin8(6, 255, 5);
} else if (viewRotation == 3) { //roll
buffer[1] = 0;//beatsin8(4, 250, 5); //tilt
buffer[2] = 0;//beatsin8(6, 255, 5); //roll
buffer[3] = beat8(1);//, 0, 255); //pan
buffer[1] = 0;//beatsin8(4, 250, 5);
buffer[2] = 0;//beatsin8(6, 255, 5);
buffer[3] = beat8(1);//, 0, 255);
} else if (viewRotation == 4) {
buffer[1] = eff->fixture.head.x;
buffer[2] = eff->fixture.head.y;
Expand All @@ -113,8 +113,8 @@ class LedModFixture:public SysModule {
// ui->setComment(var, "View rotation");
JsonArray options = ui->setOptions(var);
options.add("None");
options.add("Pan");
options.add("Tilt");
options.add("Pan");
options.add("Roll");
#ifdef STARLEDS_USERMOD_WLEDAUDIO
options.add("Moving heads GEQ");
Expand Down
Loading

0 comments on commit 20f196d

Please sign in to comment.