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

◆ compute()

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

Implements fl::XYPathGenerator.

Definition at line 53 of file xypath_impls.cpp.

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

References PI, x, and y.