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

◆ drawFlowVectors()

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

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

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