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

◆ easeInSine16()

u16 fl::easeInSine16 ( u16 i)

16-bit sine ease-in function Takes an input value 0-65535 and returns an eased value 0-65535

Definition at line 265 of file ease.cpp.

265 {
266 // ease-in sine: 1 - cos(t * π/2)
267 // Handle boundary conditions explicitly
268 if (i == 0)
269 return 0;
270 // Remove the hard-coded boundary for 65535 and let math handle it
271
272 // For 16-bit: use cos32 for efficiency and accuracy
273 // Map i from [0,65535] to [0,4194304] in cos32 space (zero to quarter wave)
274 // Formula: 1 - cos(t * π/2) where t goes from 0 to 1
275 // sin32/cos32 quarter cycle is 16777216/4 = 4194304
276 u32 angle = ((fl::u64)i * 4194304ULL) / 65535ULL;
277 i32 cos_result = fl::cos32(angle);
278
279 // Convert cos32 output and apply easing formula: 1 - cos(t * π/2)
280 // cos32 output range is [-2147418112, 2147418112]
281 // At t=0: cos(0) = 2147418112, result should be 0
282 // At t=1: cos(π/2) = 0, result should be 65535
283
284 const fl::i64 MAX_COS32 = 2147418112LL;
285
286 // Calculate: (MAX_COS32 - cos_result) and scale to [0, 65535]
287 fl::i64 adjusted = MAX_COS32 - (fl::i64)cos_result;
288
289 // Scale from [0, 2147418112] to [0, 65535]
290 fl::u64 result = (fl::u64)adjusted * 65535ULL + (MAX_COS32 >> 1); // Add half for rounding
291 u16 final_result = (u16)(result / (fl::u64)MAX_COS32);
292
293 return final_result;
294}
Result type for promise operations.
static FASTLED_FORCE_INLINE i32 cos32(u32 angle)
Definition sin32.h:45

References cos32().

Referenced by ease16(), and ease16().

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