FastLED 3.10.8
Loading...
Searching...
No Matches
xypath_impls.h
Go to the documentation of this file.
1
2#pragma once
3
4// This is a drawing/graphics related class.
5//
6// XYPath represents a parameterized (x,y) path. The input will always be
7// an alpha value between 0->1 (float) or 0->0xffff (u16).
8// A look up table can be used to optimize path calculations when steps > 0.
9//
10// We provide common paths discovered throughout human history, for use in
11// your animations.
12
13#include "fl/math/lut.h" // IWYU pragma: keep
14#include "fl/math/math.h" // IWYU pragma: keep
15#include "fl/stl/shared_ptr.h" // For FASTLED_SHARED_PTR macros
16#include "fl/gfx/tile2x2.h" // IWYU pragma: keep
17#include "fl/math/transform.h"
19#include "fl/stl/vector.h"
20#include "fl/log/log.h" // IWYU pragma: keep
21#include "fl/stl/noexcept.h"
22
23namespace fl {
24
25class XYRasterU8Sparse; // IWYU pragma: keep
26template <typename T> class function; // IWYU pragma: keep
27
28// Smart pointers for the XYPath family.
42
43// FASTLED_SHARED_PTR(LissajousPath);
44
45// BaseClasses.
46// Controllable parameter base class. Each subtype has a transform and
47// brightness.
49 public:
50 // Reserved for future use.
52 float brightness = 1.0f; // 0: off, 1: full brightness
53};
54
55// Base class for the actual path generator.
57 public:
58 virtual ~XYPathGenerator() FL_NO_EXCEPT = default; // Add virtual destructor for proper cleanup
59 virtual const string name() const FL_NO_EXCEPT = 0;
60 virtual vec2f compute(float alpha) FL_NO_EXCEPT = 0;
61 // No writes when returning false.
62 virtual bool hasDrawBounds(rect<i16> *bounds) FL_NO_EXCEPT {
63 FASTLED_UNUSED(bounds);
64 return false;
65 }
66};
67
69// Begin parameter classes.
71 public:
72 float x0 = -1.0f; // Start x coordinate
73 float y0 = 0.0f; // Start y coordinate
74 float x1 = 1.0f; // End x coordinate
75 float y1 = 0.0f; // End y coordinate
76};
77
79 public:
80 float c = 4.0f; // Scaling factor
81 float angle = 137.5f; // Divergence angle in degrees
82};
83
85 public:
86 u8 n = 3; // Numerator parameter (number of petals)
87 u8 d = 1; // Denominator parameter
88};
89
91 public:
92 float a = 1.0f; // Scaling parameter a
93 float b = 1.0f; // Scaling parameter b
94 float m = 3.0f; // Symmetry parameter (number of rotational symmetries)
95 float n1 = 1.0f; // Shape parameter n1
96 float n2 = 1.0f; // Shape parameter n2
97 float n3 = 100.0f; // Shape parameter n3
98};
99
101 public:
103
104 // Add a point to the path
105 void addPoint(vec2f p) FL_NO_EXCEPT { points.push_back(p); }
106
107 // Add a point with separate x,y coordinates
108 void addPoint(float x, float y) FL_NO_EXCEPT { points.push_back(vec2f(x, y)); }
109
110 // Clear all control points
111 void clear() FL_NO_EXCEPT { points.clear(); }
112
113 // Get the number of control points
114 fl::size size() const FL_NO_EXCEPT { return points.size(); }
115
116 // Vector of control points
118};
119
121// Begin implementations of common XYPaths
122
124 public:
125 PointPath(float x, float y) FL_NO_EXCEPT;
127 vec2f compute(float alpha) FL_NO_EXCEPT override;
128 const string name() const FL_NO_EXCEPT override;
129 void set(float x, float y) FL_NO_EXCEPT;
130 void set(vec2f p) FL_NO_EXCEPT;
131
132 private:
134};
135
136class LinePath : public XYPathGenerator {
137 public:
138 LinePath(const LinePathParamsPtr &params = fl::make_shared<LinePathParams>()) FL_NO_EXCEPT;
139 LinePath(float x0, float y0, float x1, float y1) FL_NO_EXCEPT;
140 vec2f compute(float alpha) FL_NO_EXCEPT override;
141 const string name() const FL_NO_EXCEPT override;
142 void set(float x0, float y0, float x1, float y1) FL_NO_EXCEPT;
143 void set(const LinePathParams &p) FL_NO_EXCEPT;
144
146 const LinePathParams &params() const FL_NO_EXCEPT;
147
148 private:
150};
151
153 public:
155 vec2f compute(float alpha) FL_NO_EXCEPT override;
156 const string name() const FL_NO_EXCEPT override;
157};
158
160 public:
162 vec2f compute(float alpha) FL_NO_EXCEPT override;
163 const string name() const FL_NO_EXCEPT override;
164};
165
167 public:
168 ArchimedeanSpiralPath(u8 turns = 3, float radius = 1.0f) FL_NO_EXCEPT;
169 vec2f compute(float alpha) FL_NO_EXCEPT override;
170 const string name() const FL_NO_EXCEPT override;
171
172 void setTurns(u8 turns) FL_NO_EXCEPT;
173 void setRadius(float radius) FL_NO_EXCEPT;
174
175 private:
176 u8 mTurns; // Number of spiral turns
177 float mRadius; // Maximum radius of the spiral
178};
179
180class RosePath : public XYPathGenerator {
181 public:
182 // n and d determine the shape of the rose curve
183 // For n/d odd: produces n petals
184 // For n/d even: produces 2n petals
185 // For n and d coprime: produces n petals if n is odd, 2n petals if n is
186 // even
188 RosePath(u8 n = 3, u8 d = 1) FL_NO_EXCEPT;
189 vec2f compute(float alpha) FL_NO_EXCEPT override;
190 const string name() const FL_NO_EXCEPT override;
191
193 const RosePathParams &params() const FL_NO_EXCEPT;
194
195 void setN(u8 n) FL_NO_EXCEPT;
196 void setD(u8 d) FL_NO_EXCEPT;
197
198 private:
200};
201
203 public:
204 // c is a scaling factor, angle is the divergence angle in degrees (often
205 // 137.5° - the golden angle)
208 vec2f compute(float alpha) FL_NO_EXCEPT override;
209 const string name() const FL_NO_EXCEPT override;
210
213
214 private:
216};
217
219 public:
220 // Gielis superformula parameters:
221 // a, b: scaling parameters
222 // m: symmetry parameter (number of rotational symmetries)
223 // n1, n2, n3: shape parameters
226 vec2f compute(float alpha) FL_NO_EXCEPT override;
227 const string name() const FL_NO_EXCEPT override;
228
231
232 void setA(float a) FL_NO_EXCEPT;
233 void setB(float b) FL_NO_EXCEPT;
234 void setM(float m) FL_NO_EXCEPT;
235 void setN1(float n1) FL_NO_EXCEPT;
236 void setN2(float n2) FL_NO_EXCEPT;
237 void setN3(float n3) FL_NO_EXCEPT;
238
239 private:
241};
242
247 public:
249
252
254 void addPoint(float x, float y) FL_NO_EXCEPT;
255
257 void clear() FL_NO_EXCEPT;
258
260 fl::size size() const FL_NO_EXCEPT;
261
262 vec2f compute(float alpha) FL_NO_EXCEPT override;
263 const string name() const FL_NO_EXCEPT override;
264
266 const CatmullRomParams &params() const FL_NO_EXCEPT;
267
268 private:
270
271 // Helper function to interpolate between points using Catmull-Rom spline
272 vec2f interpolate(const vec2f &p0, const vec2f &p1, const vec2f &p2,
273 const vec2f &p3, float t) const FL_NO_EXCEPT;
274};
275
276// Smart pointer for CatmullRomPath
278
279} // namespace fl
const string name() const FL_NO_EXCEPT override
ArchimedeanSpiralPath(u8 turns=3, float radius=1.0f) FL_NO_EXCEPT
void setTurns(u8 turns) FL_NO_EXCEPT
vec2f compute(float alpha) FL_NO_EXCEPT override
void setRadius(float radius) FL_NO_EXCEPT
void clear() FL_NO_EXCEPT
CatmullRomParams() FL_NO_EXCEPT
void addPoint(vec2f p) FL_NO_EXCEPT
void addPoint(float x, float y) FL_NO_EXCEPT
fl::size size() const FL_NO_EXCEPT
fl::vector< vec2f > points
fl::shared_ptr< CatmullRomParams > mParams
CatmullRomPath(const fl::shared_ptr< CatmullRomParams > &p=fl::make_shared< CatmullRomParams >()) FL_NO_EXCEPT
const string name() const FL_NO_EXCEPT override
CatmullRomParams & params() FL_NO_EXCEPT
vec2f compute(float alpha) FL_NO_EXCEPT override
fl::size size() const FL_NO_EXCEPT
Get the number of control points.
vec2f interpolate(const vec2f &p0, const vec2f &p1, const vec2f &p2, const vec2f &p3, float t) const FL_NO_EXCEPT
void addPoint(vec2f p) FL_NO_EXCEPT
Add a point in [0,1]² to the path.
void clear() FL_NO_EXCEPT
Clear all control points.
Catmull–Rom spline through arbitrary points.
CirclePath() FL_NO_EXCEPT
const string name() const FL_NO_EXCEPT override
vec2f compute(float alpha) FL_NO_EXCEPT override
fl::shared_ptr< GielisCurveParams > mParams
void setN1(float n1) FL_NO_EXCEPT
const string name() const FL_NO_EXCEPT override
GielisCurveParams & params() FL_NO_EXCEPT
GielisCurvePath(const fl::shared_ptr< GielisCurveParams > &p=fl::make_shared< GielisCurveParams >()) FL_NO_EXCEPT
void setB(float b) FL_NO_EXCEPT
void setN2(float n2) FL_NO_EXCEPT
void setN3(float n3) FL_NO_EXCEPT
void setA(float a) FL_NO_EXCEPT
vec2f compute(float alpha) FL_NO_EXCEPT override
void setM(float m) FL_NO_EXCEPT
vec2f compute(float alpha) FL_NO_EXCEPT override
HeartPath() FL_NO_EXCEPT
const string name() const FL_NO_EXCEPT override
const string name() const FL_NO_EXCEPT override
void set(float x0, float y0, float x1, float y1) FL_NO_EXCEPT
fl::shared_ptr< LinePathParams > mParams
LinePathParams & params() FL_NO_EXCEPT
LinePath(const LinePathParamsPtr &params=fl::make_shared< LinePathParams >()) FL_NO_EXCEPT
vec2f compute(float alpha) FL_NO_EXCEPT override
const string name() const FL_NO_EXCEPT override
PhyllotaxisPath(const fl::shared_ptr< PhyllotaxisParams > &p=fl::make_shared< PhyllotaxisParams >()) FL_NO_EXCEPT
fl::shared_ptr< PhyllotaxisParams > mParams
PhyllotaxisParams & params() FL_NO_EXCEPT
vec2f compute(float alpha) FL_NO_EXCEPT override
void set(float x, float y) FL_NO_EXCEPT
vec2f compute(float alpha) FL_NO_EXCEPT override
const string name() const FL_NO_EXCEPT override
PointPath(float x, float y) FL_NO_EXCEPT
fl::shared_ptr< RosePathParams > mParams
void setN(u8 n) FL_NO_EXCEPT
void setD(u8 d) FL_NO_EXCEPT
const string name() const FL_NO_EXCEPT override
RosePath(const fl::shared_ptr< RosePathParams > &p=fl::make_shared< RosePathParams >()) FL_NO_EXCEPT
RosePathParams & params() FL_NO_EXCEPT
vec2f compute(float alpha) FL_NO_EXCEPT override
virtual bool hasDrawBounds(rect< i16 > *bounds) FL_NO_EXCEPT
virtual const string name() const FL_NO_EXCEPT=0
virtual vec2f compute(float alpha) FL_NO_EXCEPT=0
virtual ~XYPathGenerator() FL_NO_EXCEPT=default
TransformFloat transform
Centralized logging categories for FastLED hardware interfaces and subsystems.
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
vec2< float > vec2f
Definition geometry.h:333
Base definition for an LED controller.
#define FASTLED_UNUSED(x)
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577