FastLED 3.10.8
Loading...
Searching...
No Matches

◆ drawFlowVectors()

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

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

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

References fl::fabsf(), fl::FL_NO_EXCEPT, 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: