@@ -823,7 +823,7 @@ class TetrixEffect : public Node {
823823 // if the speed is set to 1 this should take 5s and at 255 it should take 0.25s
824824 // as this is dependant on layer->size.x it should be taken into account and the fact that effect runs every FRAMETIME s
825825 int speed = speedControl ? speedControl : random8 (1 , 255 );
826- speed = map (speed, 1 , 255 , 5000 , 250 ); // time taken for full (layer->size.x) drop
826+ speed = map (speed, 1 , 255 , 40000 , 250 ); // time in ms taken for full (layer->size.x) drop
827827 drops[y].speed = float (layer->size .x * FRAMETIME) / float (speed); // set speed
828828 drops[y].pos = layer->size .x ; // start at end of segment (no need to subtract 1)
829829 if (!oneColor) drops[y].col = random8 (0 , 15 ) << 4 ; // limit color choices so there is enough HUE gap
@@ -1583,74 +1583,95 @@ class DripEffect : public Node {
15831583 uint8_t gravityControl = 128 ;
15841584 uint8_t drips = 4 ;
15851585 uint8_t swell = 4 ;
1586- bool invert = false ;
15871586
15881587 void setup () override {
15891588 addControl (gravityControl, " gravity" , " slider" , 1 , 255 );
15901589 addControl (drips, " drips" , " slider" , 1 , 6 );
15911590 addControl (swell, " swell" , " slider" , 1 , 6 );
1592- addControl (invert, " invert" , " checkbox" );
15931591 }
15941592
1595- // binding of loop persistent values (pointers)
1596- Spark drops[maxNumDrops];
1593+ Spark (*drops)[maxNumDrops] = nullptr ; // [maxColumns][maxNumBalls];
1594+ uint16_t dropsSize = 0 ;
1595+
1596+ ~DripEffect () override {
1597+ freeMB (drops);
1598+ freeMB (colors);
1599+ }
1600+
1601+ void onSizeChanged (const Coord3D& prevSize) override {
1602+ Spark (*newAlloc)[maxNumDrops] = reallocMB<Spark[maxNumDrops]>(drops, layer->size .y );
1603+
1604+ if (newAlloc) {
1605+ drops = newAlloc;
1606+ dropsSize = layer->size .x ;
1607+ } else {
1608+ EXT_LOGE (ML_TAG, " (re)allocate drops failed" );
1609+ }
1610+ }
1611+
1612+ enum DropState { init = 0 , forming = 1 , falling = 2 , bouncing = 5 };
15971613
15981614 void loop () override {
15991615 // layer->fadeToBlackBy(90);
16001616 layer->fill_solid (CRGB::Black);
16011617
1602- float gravity = -0 .0005f - (gravityControl / 25000 .0f ); // increased gravity (50000 to 25000)
1618+ float gravity = -0 .0005f - (gravityControl / 50000 .0f ); // increased gravity (50000 to 25000)
16031619 gravity *= max (1 , layer->size .x - 1 );
1620+ gravity /= 100 ; // don't know why it is falling so fast so slowed it down...
16041621 int sourcedrop = 12 ;
16051622
1606- for (int j = 0 ; j < drips; j++) {
1607- if (drops[j].colIndex == 0 ) { // init
1608- drops[j].pos = layer->size .x - 1 ; // start at end
1609- drops[j].vel = 0 ; // speed
1610- drops[j].col = sourcedrop; // brightness
1611- drops[j].colIndex = 1 ; // drop state (0 init, 1 forming, 2 falling, 5 bouncing)
1612- drops[j].velX = (uint32_t )ColorFromPalette (layerP.palette , random8 ()); // random color
1613- }
1614- CRGB dropColor = drops[j].velX ;
1623+ for (int y = 0 ; y < dropsSize; y++) {
1624+ for (int j = 0 ; j < drips; j++) {
1625+ if (drops[y][j].colIndex == init) { // init
1626+ drops[y][j].pos = layer->size .x - 1 ; // start at end
1627+ drops[y][j].vel = 0 ; // speed
1628+ drops[y][j].col = sourcedrop; // brightness
1629+ drops[y][j].colIndex = forming; // drop state
1630+ CRGB c = ColorFromPalette (layerP.palette , random8 ()); // random color by MoonModules, hacked into velX of type float
1631+ memcpy (&drops[y][j].velX , &c, sizeof (CRGB));
1632+ }
1633+ CRGB dropColor;
1634+ memcpy (&dropColor, &drops[y][j].velX , sizeof (CRGB)); // hacked back
16151635
1616- layer->setRGB (invert ? 0 : layer->size .x - 1 , blend (CRGB::Black, dropColor, sourcedrop)); // water source
1617- if (drops[j].colIndex == 1 ) {
1618- if (drops[j].col > 255 ) drops[j].col = 255 ;
1619- layer-> setRGB (invert ? layer->size . x - 1 - drops[j]. pos : drops [j].pos , blend (CRGB::Black, dropColor, drops[j].col ));
1636+ layer->setRGB (Coord3D ( layer->size .x - 1 , y) , blend (CRGB::Black, dropColor, sourcedrop)); // water source
1637+ if (drops[y][ j].colIndex == forming ) {
1638+ if (drops[y][ j].col > 255 ) drops[y] [j].col = 255 ;
1639+ layer->setRGB ( Coord3D ( drops[y] [j].pos , y), blend (CRGB::Black, dropColor, drops[y] [j].col ));
16201640
1621- drops[j].col += swell; // swelling
1641+ drops[y] [j].col += swell; // swelling
16221642
1623- if (random16 () <= drops[j].col * swell * swell / 10 ) { // random drop
1624- drops[j].colIndex = 2 ; // fall
1625- drops[j].col = 255 ;
1626- }
1627- }
1628- if (drops[j].colIndex > 1 ) { // falling
1629- if (drops[j].pos > 0 ) { // fall until end of segment
1630- drops[j].pos += drops[j].vel ;
1631- if (drops[j].pos < 0 ) drops[j].pos = 0 ;
1632- drops[j].vel += gravity; // gravity is negative
1633-
1634- for (int i = 1 ; i < 7 - drops[j].colIndex ; i++) { // some minor math so we don't expand bouncing droplets
1635- uint16_t pos = constrain (uint16_t (drops[j].pos ) + i, 0 , layer->size .x - 1 ); // this is BAD, returns a pos >= layer->size.x occasionally
1636- layer->setRGB (invert ? layer->size .x - 1 - pos : pos, blend (CRGB::Black, dropColor, drops[j].col / i)); // spread pixel with fade while falling
1643+ if (random16 () <= drops[y][j].col * swell * swell / 10 ) { // random drop
1644+ drops[y][j].colIndex = falling;
1645+ drops[y][j].col = 255 ;
16371646 }
1647+ }
1648+ if (drops[y][j].colIndex > forming) { // falling
1649+ if (drops[y][j].pos > 0 ) { // fall until end of segment
1650+ drops[y][j].pos += drops[y][j].vel ;
1651+ if (drops[y][j].pos < 0 ) drops[y][j].pos = 0 ;
1652+ drops[y][j].vel += gravity; // gravity is negative
1653+
1654+ for (int i = 1 ; i < 7 - drops[y][j].colIndex ; i++) { // some minor math so we don't expand bouncing droplets
1655+ uint16_t pos = constrain (uint16_t (drops[y][j].pos ) + i, 0 , layer->size .x - 1 ); // this is BAD, returns a pos >= layer->size.x occasionally
1656+ layer->setRGB (Coord3D (pos, y), blend (CRGB::Black, dropColor, drops[y][j].col / i)); // spread pixel with fade while falling
1657+ }
16381658
1639- if (drops[j].colIndex > 2 ) { // during bounce, some water is on the floor
1640- layer->setRGB (invert ? layer->size .x - 1 : 0 , blend (dropColor, CRGB::Black, drops[j].col ));
1641- }
1642- } else { // we hit bottom
1643- if (drops[j].colIndex > 2 ) { // already hit once, so back to forming
1644- drops[j].colIndex = 0 ;
1645- // drops[j].col = sourcedrop;
1646-
1647- } else {
1648- if (drops[j].colIndex == 2 ) { // init bounce
1649- drops[j].vel = -drops[j].vel / 4 ; // reverse velocity with damping
1650- drops[j].pos += drops[j].vel ;
1659+ if (drops[y][j].colIndex > falling) { // during bounce, some water is on the floor
1660+ layer->setRGB (Coord3D (0 , y), blend (dropColor, CRGB::Black, drops[y][j].col ));
1661+ }
1662+ } else { // we hit bottom
1663+ if (drops[y][j].colIndex > falling) { // already hit once, so back to forming
1664+ drops[y][j].colIndex = init;
1665+ drops[y][j].col = sourcedrop;
1666+
1667+ } else {
1668+ if (drops[y][j].colIndex == falling) { // init bounce
1669+ drops[y][j].vel = -drops[y][j].vel / 4 ; // reverse velocity with damping
1670+ drops[y][j].pos += drops[y][j].vel ;
1671+ }
1672+ drops[y][j].col = sourcedrop * 2 ;
1673+ drops[y][j].colIndex = bouncing;
16511674 }
1652- drops[j].col = sourcedrop * 2 ;
1653- drops[j].colIndex = 5 ; // bouncing
16541675 }
16551676 }
16561677 }
0 commit comments