FastLED 3.9.15
Loading...
Searching...
No Matches

◆ drawFlowVectors()

void fl::FlowFieldFloat::drawFlowVectors ( fl::span< CRGB > leds)
private

Definition at line 357 of file flowfield.cpp.hpp.

357 {
358 int w = (int)getWidth();
359 int h = (int)getHeight();
360
361 // Helper: plot a single subpixel point via Tile2x2 through the XYMap.
362 auto plotTile = [&](const CRGB &color, float px, float py,
363 bool horiz) {
364 int ix = (int)floorf(px);
365 int iy = (int)floorf(py);
366 float fx = px - (float)ix;
367 float fy = py - (float)iy;
368 Tile2x2_u8 tile;
369 tile.setOrigin((u16)ix, (u16)iy);
370 if (horiz) {
371 // X profile: subpixel along y only (one column wide)
372 tile.at(0, 0) = (u8)((1.0f - fy) * 255.0f);
373 tile.at(1, 0) = 0;
374 tile.at(0, 1) = (u8)(fy * 255.0f);
375 tile.at(1, 1) = 0;
376 } else {
377 // Y profile: subpixel along x only (one row tall)
378 tile.at(0, 0) = (u8)((1.0f - fx) * 255.0f);
379 tile.at(1, 0) = (u8)(fx * 255.0f);
380 tile.at(0, 1) = 0;
381 tile.at(1, 1) = 0;
382 }
383 tile.draw(color, mXyMap, leds);
384 };
385
386 // Display amplitude: 0.3 = profile uses ~30% of the display around center.
387 constexpr float amp = 0.3f;
388
389 // X profile (per-column): plot value as y-position — cyan.
390 // Interpolate between consecutive columns to fill gaps.
391 CRGB xColor(0, 255, 255);
392 float centerY = (float)(h - 1) * 0.5f;
393 float prevPy = 0.0f;
394 for (int x = 0; x < w; x++) {
395 float val = mXProf[x]; // [-1, 1]
396 float py = centerY - val * amp * centerY;
397 plotTile(xColor, (float)x, py, true);
398 if (x > 0) {
399 float dy = py - prevPy;
400 int gap = (int)fabsf(dy);
401 for (int s = 1; s < gap; s++) {
402 float t = (float)s / (float)gap;
403 float midY = prevPy + dy * t;
404 float midX = (float)(x - 1) + t;
405 plotTile(xColor, midX, midY, true);
406 }
407 }
408 prevPy = py;
409 }
410
411 // Y profile (per-row): plot value as x-position — yellow.
412 // Interpolate between consecutive rows to fill gaps.
413 CRGB yColor(255, 255, 0);
414 float centerX = (float)(w - 1) * 0.5f;
415 float prevPx = 0.0f;
416 for (int y = 0; y < h; y++) {
417 float val = mYProf[y]; // [-1, 1]
418 float px = centerX + val * amp * centerX;
419 plotTile(yColor, px, (float)y, false);
420 if (y > 0) {
421 float dx = px - prevPx;
422 int gap = (int)fabsf(dx);
423 for (int s = 1; s < gap; s++) {
424 float t = (float)s / (float)gap;
425 float midX = prevPx + dx * t;
426 float midY = (float)(y - 1) + t;
427 plotTile(yColor, midX, midY, false);
428 }
429 }
430 prevPx = px;
431 }
432}
fl::CRGB leds[NUM_LEDS]
fl::vector< float > mYProf
Per-row values; drives horizontal shift.
Definition flowfield.h:352
fl::vector< float > mXProf
Per-column values; drives vertical shift.
Definition flowfield.h:351
XYMap mXyMap
Definition fx2d.h:30
u16 getWidth() const
Definition fx2d.h:24
u16 getHeight() const
Definition fx2d.h:23
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
float floorf(float value) FL_NOEXCEPT
Definition math.h:304
float fabsf(float value) FL_NOEXCEPT
Definition math.h:508

References fl::fabsf(), fl::floorf(), fl::Fx2d::getHeight(), fl::Fx2d::getWidth(), leds, mXProf, fl::Fx2d::mXyMap, mYProf, fl::Tile2x2_u8::setOrigin(), fl::t, fl::x, and fl::y.

Referenced by drawImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: