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

◆ compute()

vec2f fl::RosePath::compute ( float alpha)
overridevirtual

Implements fl::XYPathGenerator.

Definition at line 112 of file xypath_impls.cpp.

112 {
113 // Parametric equation for a rose curve (rhodonea)
114 // α in [0,1] → (x,y) on the rose curve
115
116 // Map alpha to the full range needed for the rose
117 // For a complete rose, we need to go through k*PI radians where k is:
118 // - k = n if n is odd and d is 1
119 // - k = 2n if n is even and d is 1
120 // - k = n*d if n and d are coprime
121 // For simplicity, we'll use 2*PI*n as a good approximation
122 float theta = alpha * 2.0f * PI * params().n;
123
124 // Calculate the radius using the rose formula: r = cos(n*θ/d)
125 // We use cosine for a rose that starts with a petal at theta=0
126 float r = cosf(params().n * theta / params().d);
127
128 // Scale to ensure the rose fits within [-1, 1] range
129 // The absolute value ensures we get the proper shape
130 r = fabsf(r);
131
132 // Convert polar coordinates (r, theta) to Cartesian (x, y)
133 float x = r * cosf(theta);
134 float y = r * sinf(theta);
135
136 return vec2f(x, y);
137}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
RosePathParams & params()
#define PI
Definition math_macros.h:57
vec2< float > vec2f
Definition geometry.h:151

References fl::RosePathParams::n, params(), PI, x, and y.

+ Here is the call graph for this function: