Skip to content

Commit 88607ec

Browse files
committed
Implemented changes to Elastic Collisions recommended by CodeRabbit with some corrections.
1 parent 8056492 commit 88607ec

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

usermods/elastic_collisions/Elastic_Collisions.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class MBSphere
145145
// Normalize direction
146146
if (length << 1 == 0) {
147147
// handle gracefully, but this shouldn't happen.
148-
Serial.println("At 0 #1");
148+
DEBUG_PRINTLN("At 0 #1");
149149
return;
150150
}
151151
nfixed scale = fixedDiv(dist - length, length << 1);
@@ -170,7 +170,7 @@ class MBSphere
170170
nfixed dist = fixedDist(nx, ny);
171171
while (dist == 0) {
172172
// handle gracefully
173-
// Serial.println("Two objects on top of each other!");
173+
// DEBUG_PRINTLN("Two objects on top of each other!");
174174

175175
x += 1 << (SPHERE_PREC_SHIFT -2);
176176
nx += 1 << (SPHERE_PREC_SHIFT -2);
@@ -272,6 +272,7 @@ class MBSphere
272272
{
273273
vx = 0;
274274
vy = 0;
275+
return;
275276
}
276277

277278
// Don't calculate beyond the edges of the LED array.
@@ -401,7 +402,7 @@ void mode_ElasticCollisions(void) { // by Nicholas Pisarro, Jr.
401402

402403
// Radius distribution.
403404
const int dmTableSize = 20;
404-
const uint8_t PROGMEM dmPercentages[20] = {40, 20, 10, 4, 3, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3};
405+
static const uint8_t PROGMEM dmPercentages[20] = {40, 20, 10, 4, 3, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3};
405406

406407
// Reinitialize evertying if the number of spheres has changed.
407408
// (We need a separate counter for the number wanted, vs. the number actually initialized.)
@@ -424,8 +425,8 @@ void mode_ElasticCollisions(void) { // by Nicholas Pisarro, Jr.
424425
nfixed radius = (7 << 16) + ((((uint64_t)skewedRandom(random(100), dmTableSize, dmPercentages) * complementUniformity << 16) / 10000) * (23 << 16) >> 16);// 7-30
425426
// radius = 30 << SPHERE_PREC_SHIFT;
426427
nfixed massFactor = MBSphere::fixedDiv((11 << SPHERE_PREC_SHIFT), radius); // Big things should move slower to keep momentum down.
427-
nfixed vx = (-50.0 + random(100)) * massFactor / 5.0; // ±10
428-
nfixed vy = (-50.0 + random(100)) * massFactor * complementUniformity / 500.0; // ±10
428+
nfixed vx = (-50 + (nfixed)hw_random(100)) * massFactor / 5; // ±10
429+
nfixed vy = (-50 + (nfixed)hw_random(100)) * massFactor * complementUniformity / 500; // ±10
429430
radius /= 10;
430431
vx /= 10;
431432
vy /= 10;
@@ -479,9 +480,8 @@ void mode_ElasticCollisions(void) { // by Nicholas Pisarro, Jr.
479480

480481
// If it is time to do something.
481482
if (millis() > SEGMENT.step) {
482-
// Turm off all the LEDS.
483-
for (int i = 0; i < SEGLEN; ++i)
484-
SEGMENT.setPixelColor(i, CRGB::Black);
483+
// Turn off all the LEDS.
484+
SEGMENT.fill(BLACK);
485485

486486
// Draw the spheres.
487487
for (int i = 0; i < (SEGMENT.aux0 & SPHERES_ALLOCATED); ++i)

usermods/elastic_collisions/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ When you save an effect in *Presets*, it is saved as an ordinal effect number ca
2929

3030
## Parameters
3131

32-
1. **Speed** The average initial velocity of balls over a wide ranage.
32+
1. **Speed** The average initial velocity of balls over a wide range.
3333
2. **Count** 1-30 balls
3434
3. **Uniformity** 0-100%. 100% uniformity is special as discussed above.
35-
4. **Lifetime** Regenration time from 15 seconds to 1 hour.
35+
4. **Lifetime** Regeneration time from 15 seconds to 1 hour.

0 commit comments

Comments
 (0)