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

◆ compute()

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

Implements fl::XYPathGenerator.

Definition at line 54 of file xypath_impls.cpp.hpp.

54 {
55 // Parametric equation for a heart shape
56 // α in [0,1] → (x,y) on the heart curve
57 float t = alpha * 2.0f * FL_PI;
58
59 // Heart formula based on a modified cardioid with improved aesthetics
60 float x = 16.0f * powf(sinf(t), 3);
61
62 // Modified y formula for a more balanced heart shape
63 // This creates a fuller bottom and more defined top curve
64 float y = -(13.0f * cosf(t) - 5.0f * cosf(2.0f * t) -
65 2.0f * cosf(3.0f * t) - cosf(4.0f * t));
66
67 // Scale to fit in [-1, 1] range
68 // The 16.0f divisor for x ensures x is in [-1, 1]
69 x /= 16.0f;
70
71 // Scale y to ensure it's in [-1, 1]
72 // The 16.0f divisor ensures proper scaling while maintaining proportions
73 y /= -16.0f;
74
75 // Apply a slight vertical stretch to fill the [-1, 1] range better
76 y *= 1.10f;
77
78 y += 0.17f; // Adjust y to fit within the range of [-1, 1]
79
80 return vec2f(x, y);
81}
#define FL_PI
Definition math.h:26
float sinf(float value) FL_NO_EXCEPT
Definition math.h:360
vec2< float > vec2f
Definition geometry.h:333
float cosf(float value) FL_NO_EXCEPT
Definition math.h:366
float powf(float base, float exponent) FL_NO_EXCEPT
Definition math.h:444

References fl::cosf(), fl::FL_NO_EXCEPT, FL_PI, fl::powf(), fl::sinf(), fl::t, fl::x, and fl::y.

+ Here is the call graph for this function: