@@ -1583,27 +1583,31 @@ class DripEffect : public Node {
15831583 uint8_t gravityControl = 128 ;
15841584 uint8_t drips = 4 ;
15851585 uint8_t swell = 4 ;
1586+ uint8_t bounce = 128 ;
15861587
15871588 void setup () override {
15881589 addControl (gravityControl, " gravity" , " slider" , 1 , 255 );
15891590 addControl (drips, " drips" , " slider" , 1 , 6 );
15901591 addControl (swell, " swell" , " slider" , 1 , 6 );
1592+ addControl (bounce, " bounce" , " slider" );
15911593 }
15921594
15931595 Spark (*drops)[maxNumDrops] = nullptr ; // [maxColumns][maxNumBalls];
15941596 uint16_t dropsSize = 0 ;
15951597
1596- ~DripEffect () override {
1597- freeMB (drops);
1598- freeMB (colors);
1599- }
1598+ ~DripEffect () override { freeMB (drops); }
16001599
16011600 void onSizeChanged (const Coord3D& prevSize) override {
16021601 Spark (*newAlloc)[maxNumDrops] = reallocMB<Spark[maxNumDrops]>(drops, layer->size .y );
16031602
16041603 if (newAlloc) {
16051604 drops = newAlloc;
1606- dropsSize = layer->size .x ;
1605+ dropsSize = layer->size .y ;
1606+ for (int y = 0 ; y < layer->size .y ; y++) {
1607+ for (int j = 0 ; j < maxNumDrops; j++) {
1608+ drops[y][j].colIndex = init; // Set to init so loop() will initialize properly
1609+ }
1610+ }
16071611 } else {
16081612 EXT_LOGE (ML_TAG, " (re)allocate drops failed" );
16091613 }
@@ -1646,7 +1650,7 @@ class DripEffect : public Node {
16461650 }
16471651 }
16481652 if (drops[y][j].colIndex > forming) { // falling
1649- if (drops[y][j].pos > 0 ) { // fall until end of segment
1653+ if (drops[y][j].pos > 0 ) { // fall until end of layer
16501654 drops[y][j].pos += drops[y][j].vel ;
16511655 if (drops[y][j].pos < 0 ) drops[y][j].pos = 0 ;
16521656 drops[y][j].vel += gravity; // gravity is negative
@@ -1659,15 +1663,17 @@ class DripEffect : public Node {
16591663 if (drops[y][j].colIndex > falling) { // during bounce, some water is on the floor
16601664 layer->setRGB (Coord3D (0 , y), blend (dropColor, CRGB::Black, drops[y][j].col ));
16611665 }
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-
1666+ } else { // we hit bottom, pos <= 0
1667+ if (drops[y][j].colIndex > falling) { // bouncing, already hit once, so back to forming
1668+ if ( drops[y][j].pos <= 0 ) {
1669+ drops[y][j].colIndex = init ;
1670+ }
16671671 } else {
1668- if (drops[y][j].colIndex == falling) { // init bounce
1669- drops[y][j].vel = -drops[y][j].vel / 4 ; // reverse velocity with damping
1672+ if (drops[y][j].colIndex == falling) { // init bounce
1673+ drops[y][j].vel = -drops[y][j].vel ;// / 4.0; // reverse velocity with damping
1674+ // drops[y][j].vel = -drops[y][j].vel / (bounce / 64.0); // reverse velocity with damping
16701675 drops[y][j].pos += drops[y][j].vel ;
1676+ if (drops[y][j].pos <= 1 ) drops[y][j].pos = 1 ;
16711677 }
16721678 drops[y][j].col = sourcedrop * 2 ;
16731679 drops[y][j].colIndex = bouncing;
0 commit comments