MCPcopy Create free account
hub / github.com/FastLED/FastLED / easeInOutSine16

Function easeInOutSine16

src/fl/math/ease.cpp.hpp:326–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324}
325
326u16 easeInOutSine16(u16 i) {
327 // ease-in-out sine: -(cos(π*t) - 1) / 2
328 // Handle boundary conditions explicitly
329 if (i == 0)
330 return 0;
331 if (i == 65535)
332 return 65535;
333
334 // For 16-bit: use cos32 for efficiency and accuracy
335 // Map i from [0,65535] to [0,8388608] in cos32 space (0 to half wave)
336 // Formula: (1 - cos(π*t)) / 2 where t goes from 0 to 1
337 // sin32/cos32 half cycle is 16777216/2 = 8388608
338 u32 angle = ((fl::u64)i * 8388608ULL) / 65535ULL;
339 i32 cos_result = fl::cos32(angle);
340
341 // Convert cos32 output and apply easing formula: (1 - cos(π*t)) / 2
342 // cos32 output range is [-2147418112, 2147418112]
343 // We want: (2147418112 - cos_result) / 2, then scale to [0, 65535]
344 fl::i64 adjusted = (2147418112LL - (fl::i64)cos_result) / 2;
345 return (u16)((fl::u64)adjusted * 65535ULL / 2147418112ULL);
346}
347
348// --- Gamma8 implementation ---
349

Callers 2

ease16Function · 0.85
easeInOutSine8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected