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

◆ drawFlowVectors()

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

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

904 {
905 int w = mState.width;
906 int h = mState.height;
907
908 // Helper: plot a single subpixel point via Tile2x2 through the XYMap.
909 // Uses float for the interpolation math (unoptimized debug overlay).
910 auto plotTile = [&](const CRGB &color, float px, float py,
911 bool horiz) {
912 int ix = (int)floorf(px);
913 int iy = (int)floorf(py);
914 float fx = px - (float)ix;
915 float fy = py - (float)iy;
916 Tile2x2_u8 tile;
917 tile.setOrigin((u16)ix, (u16)iy);
918 if (horiz) {
919 tile.at(0, 0) = (u8)((1.0f - fy) * 255.0f);
920 tile.at(1, 0) = 0;
921 tile.at(0, 1) = (u8)(fy * 255.0f);
922 tile.at(1, 1) = 0;
923 } else {
924 tile.at(0, 0) = (u8)((1.0f - fx) * 255.0f);
925 tile.at(1, 0) = (u8)(fx * 255.0f);
926 tile.at(0, 1) = 0;
927 tile.at(1, 1) = 0;
928 }
929 tile.draw(color, mXyMap, leds);
930 };
931
932 // Display amplitude: 0.3 = profile uses ~30% of the display around center.
933 constexpr float amp = 0.3f;
934
935 // X profile (per-column): plot value as y-position — cyan.
936 // Interpolate between consecutive columns to fill gaps.
937 CRGB xColor(0, 255, 255);
938 float centerY = (float)(h - 1) * 0.5f;
939 float prevPy = 0.0f;
940 for (int x = 0; x < w; x++) {
941 s16x16 val = s16x16::from_raw(mState.x_prof[x]); // [-1, 1]
942 float py = centerY - val.to_float() * amp * centerY;
943 plotTile(xColor, (float)x, py, true);
944 if (x > 0) {
945 float dy = py - prevPy;
946 int gap = (int)fabsf(dy);
947 for (int s = 1; s < gap; s++) {
948 float t = (float)s / (float)gap;
949 float midY = prevPy + dy * t;
950 float midX = (float)(x - 1) + t;
951 plotTile(xColor, midX, midY, true);
952 }
953 }
954 prevPy = py;
955 }
956
957 // Y profile (per-row): plot value as x-position — yellow.
958 // Interpolate between consecutive rows to fill gaps.
959 CRGB yColor(255, 255, 0);
960 float centerX = (float)(w - 1) * 0.5f;
961 float prevPx = 0.0f;
962 for (int y = 0; y < h; y++) {
963 s16x16 val = s16x16::from_raw(mState.y_prof[y]); // [-1, 1]
964 float px = centerX + val.to_float() * amp * centerX;
965 plotTile(yColor, px, (float)y, false);
966 if (y > 0) {
967 float dx = px - prevPx;
968 int gap = (int)fabsf(dx);
969 for (int s = 1; s < gap; s++) {
970 float t = (float)s / (float)gap;
971 float midX = prevPx + dx * t;
972 float midY = (float)(y - 1) + t;
973 plotTile(yColor, midX, midY, false);
974 }
975 }
976 prevPx = px;
977 }
978}
CRGB leds[1]
FlowFieldFPState mState
Definition flowfield.h:400
XYMap mXyMap
Definition fx2d.h:31
static constexpr FASTLED_FORCE_INLINE s16x16 from_raw(i32 raw) FL_NO_EXCEPT
Definition s16x16.h:56
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::s16x16::from_raw(), leds, mState, fl::Fx2d::mXyMap, fl::Tile2x2_u8::setOrigin(), fl::t, fl::s16x16::to_float(), fl::x, and fl::y.

Referenced by drawImpl().

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