| 127 | fl::XYMap xymap = fl::XYMap::constructWithUserFunction(WIDTH, HEIGHT, xy_map_function); |
| 128 | |
| 129 | void loop() { |
| 130 | // Processing does: background(0, t?9:!createCanvas(...)+W); filter(BLUR) |
| 131 | // We emulate a very light global fade + blur to leave trails. |
| 132 | // First a tiny global fade, then a mild Gaussian-ish blur. |
| 133 | fadeToBlackBy(leds, NUM_LEDS, 18); // stronger fade to prevent blowout |
| 134 | blur2d(leds, WIDTH, HEIGHT, 24, xymap); // slightly gentler blur for 32x32 |
| 135 | |
| 136 | // Spawn/overwrite one particle per frame, round-robin |
| 137 | resetParticle(ps[t % MAXP], t); |
| 138 | |
| 139 | // Update & draw all particles |
| 140 | for (int i = 0; i < MAXP; ++i) { |
| 141 | if (!ps[i].alive) |
| 142 | continue; |
| 143 | P &p = ps[i]; |
| 144 | |
| 145 | // strokeWeight(p.s *= .997) |
| 146 | p.s *= 0.997f; |
| 147 | if (p.s < 0.5f) { |
| 148 | p.alive = false; |
| 149 | continue; |
| 150 | } // cheap cull |
| 151 | |
| 152 | // a += (noise(t/99, p.g) - .5) / 9 |
| 153 | // Use 2D noise: (t/99, g). inoise8 returns 0..255; center at ~128. |
| 154 | float tOver99 = (float)t / 99.0f; |
| 155 | uint8_t n2 = inoise8((uint16_t)(tOver99 * 4096), (uint16_t)(p.g * 37)); |
| 156 | float n2c = ((int)n2 - 128) / 255.0f; // ~ -0.5 .. +0.5 |
| 157 | p.a += (n2c) / 9.0f; |
| 158 | |
| 159 | // x += cos((a)*f), y += sin(a*f) (original had (a+=...)*f inside cos) |
| 160 | float aa = p.a * (float)p.f; |
| 161 | p.x += fl::cosf(aa); |
| 162 | p.y += fl::sinf(aa); |
| 163 | |
| 164 | // draw white point with softness according to s |
| 165 | plotSoftDot(p.x, p.y, p.s); |
| 166 | } |
| 167 | |
| 168 | FastLED.show(); |
| 169 | t++; |
| 170 | // Cap frame rate a bit like Processing's draw loop |
| 171 | FastLED.delay(16); // ~60 FPS |
| 172 | } |
| 173 | |
| 174 | /*** Tips |
| 175 | * - Want sharper trails? Lower blur2d strength or raise fadeToBlackBy amount. |
nothing calls this directly
no test coverage detected