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

◆ generateState()

void fl::generateState ( const Corkscrew::Input & input,
CorkscrewState * output )

Definition at line 15 of file corkscrew.cpp.

15 {
16
17 // Calculate vertical segments based on number of turns
18 // For a single turn (2π), we want exactly 1 vertical segment
19 // For two turns (4π), we want exactly 2 vertical segments
20 // uint16_t verticalSegments = ceil(input.totalTurns);
21
22 // Calculate width based on LED density per turn
23 // float ledsPerTurn = static_cast<float>(input.numLeds) / verticalSegments;
24
25 output->mapping.clear();
26 output->width = 0; // we will change this below.
27 output->height = 0;
28
29 // If numLeds is specified, use that for mapping size instead of grid
30 output->mapping.reserve(input.numLeds);
31 // Generate LED mapping based on numLeds
32 // Note that width_step should be 1.0f/float(input.numLeds) so last led in a
33 // turn does not wrap around.
34 const float width_step =
35 1.0f / float(input.numLeds); // Corkscrew reaches max width on last led.
36 const float height_step =
37 1.0f /
38 float(input.numLeds - 1); // Corkscrew reaches max height on last led.
39 // const float led_width_factor = circumferencePerTurn / TWO_PI;
40 const float length_per_turn = input.numLeds / input.totalTurns;
41
42 for (uint16_t i = 0; i < input.numLeds; ++i) {
43 // Calculate position along the corkscrew (0.0 to 1.0)
44 const float i_f = static_cast<float>(i);
45 const float alpha_width = i_f * width_step;
46 const float alpha_height = i_f * height_step;
47 const float width_before_mod = alpha_width * input.totalLength;
48 const float height = alpha_height * input.totalHeight;
49 const float width = fmodf(width_before_mod, length_per_turn);
50 output->mapping.push_back({width, height});
51 }
52
53 if (!output->mapping.empty()) {
54 float max_width = 0.0f;
55 float max_height = 0.0f;
56 for (const auto &point : output->mapping) {
57 max_width = MAX(max_width, point.x);
58 max_height = MAX(max_height, point.y);
59 }
60 output->width = static_cast<uint16_t>(ceilf(max_width)) + 1;
61 output->height = static_cast<uint16_t>(ceilf(max_height)) + 1;
62 }
63
64 // Apply inversion if requested
65 if (input.invert) {
66 fl::reverse(output->mapping.begin(), output->mapping.end());
67 }
68}
#define MAX(a, b)
Definition math_macros.h:11
void reverse(Iterator first, Iterator last)
Definition algorithm.h:8
fl::vector< fl::vec2f, fl::allocator_psram< fl::vec2f > > mapping
Definition corkscrew.h:71

References fl::CorkscrewState::height, fl::CorkscrewInput::invert, fl::CorkscrewState::mapping, MAX, fl::CorkscrewInput::numLeds, reverse(), fl::CorkscrewInput::totalHeight, fl::CorkscrewInput::totalLength, fl::CorkscrewInput::totalTurns, and fl::CorkscrewState::width.

Referenced by fl::Corkscrew::Corkscrew(), and fl::Corkscrew::generateState().

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