@@ -811,7 +811,7 @@ class AntEffect : public Node {
811811
812812 uint8_t antSpeed = 192 ;
813813 uint8_t nrOfAnts = MAX_ANTS / 2 ;
814- uint8_t antSizeControl = 32 / 255 ;
814+ uint8_t antSizeControl = 8 ;
815815 uint8_t blur = 0 ;
816816 bool gatherFood = true ;
817817 bool passByControl = true ;
@@ -824,34 +824,15 @@ class AntEffect : public Node {
824824 addControl (blur, " blur" , " slider" );
825825 addControl (gatherFood, " gatherFood" , " checkbox" );
826826 addControl (passByControl, " passBy" , " checkbox" );
827- }
828-
829- Ant* ants = nullptr ;
830- // uint16_t nrOfAnts = 0;
831827
832- void onSizeChanged (const Coord3D& prevSize) override {
833- Ant* newAlloc = reallocMB<Ant>(ants, MAX_ANTS);
834- if (newAlloc) {
835- ants = newAlloc;
836- // nrOfAnts = MAX_ANTS;
837- } else {
838- EXT_LOGE (ML_TAG, " (re)allocate ants failed" ); // keep old (if existed)
839- }
828+ initAnts ();
840829 }
841830
842- ~AntEffect () override { freeMB (ants); };
843-
844- void onUpdate (const Char<20 >& oldValue, const JsonObject& control) {
845- // add your custom onUpdate code here
846- if (control[" name" ] == " bpm" ) {
847- if (control[" value" ] == 0 ) {
848- }
849- }
850- }
831+ Ant ants[MAX_ANTS];
851832
852833 // Helper function to calculate ant color
853834 CRGB getAntColor (int antIndex, int numAnts, bool usePalette) {
854- // if (usePalette)
835+ // if (usePalette)
855836 return ColorFromPalette (layerP.palette , antIndex * 255 / numAnts);
856837 // Alternate between two colors for default palette
857838 // return (antIndex % 3 == 1) ? SEGCOLOR(0) : SEGCOLOR(2);
@@ -868,23 +849,22 @@ class AntEffect : public Node {
868849 }
869850 }
870851
871- // Initialize ants on first call
852+ // Initialize ants on first call
872853 void initAnts () {
873- int confusedAntIndex = random (0 , numAnts); // the first random ant to go backwards
874-
875- for (int i = 0 ; i < MAX_ANTS; i++) {
876- ants[i].lastBumpUpdate = millis ();
854+ int confusedAntIndex = random (0 , numAnts); // the first random ant to go backwards
877855
878- // Random velocity
879- float velocity = VELOCITY_MIN + (VELOCITY_MAX - VELOCITY_MIN) * random16 (1000 , 5000 ) / 5000 .0f ;
880- // One random ant moves in opposite direction
881- ants[i].velocity = (i == confusedAntIndex) ? -velocity : velocity;
882- // Random starting position (0.0 to 1.0)
883- ants[i].position = random16 (0 , 10000 ) / 10000 .0f ;
884- // Ants don't have food yet
885- ants[i].hasFood = false ;
886- }
856+ for (int i = 0 ; i < MAX_ANTS; i++) {
857+ ants[i].lastBumpUpdate = millis ();
887858
859+ // Random velocity
860+ float velocity = VELOCITY_MIN + (VELOCITY_MAX - VELOCITY_MIN) * random16 (1000 , 5000 ) / 5000 .0f ;
861+ // One random ant moves in opposite direction
862+ ants[i].velocity = (i == confusedAntIndex) ? -velocity : velocity;
863+ // Random starting position (0.0 to 1.0)
864+ ants[i].position = random16 (0 , 10000 ) / 10000 .0f ;
865+ // Ants don't have food yet
866+ ants[i].hasFood = false ;
867+ }
888868 }
889869
890870 unsigned numAnts;
@@ -958,7 +938,7 @@ class AntEffect : public Node {
958938 unsigned pixelPosition = roundf (newPosition * (layer->nrOfLights - 1 ));
959939
960940 // Determine ant color
961- CRGB antColor = getAntColor (i, numAnts, true ); // always use palette for now
941+ CRGB antColor = getAntColor (i, numAnts, true ); // always use palette for now
962942
963943 // Render ant pixels
964944 for (int pixelOffset = 0 ; pixelOffset < antSize; pixelOffset++) {
0 commit comments