PixelKey
NeoPixel USB Key
Loading...
Searching...
No Matches
Fade Keyframe

Keyframe for transitioning between two or more colors. More...

Data Structures

struct  point_t
 Single point on a cartesian plane. More...
 
struct  cubic_bezier_t
 Pair of control points for a cubic bezier curve where the start is (0,0) and end is (1,1). More...
 
struct  keyframe_fade_t
 Fade keyframe. More...
 

Macros

#define KEYFRAME_FADE_COLORS_INPUT_MAX_LENGTH   (15)
 Maximum number of colors allowed to be input by the user.
 
#define KEYFRAME_FADE_COLORS_MAX_LENGTH   (KEYFRAME_FADE_COLORS_INPUT_MAX_LENGTH + 1)
 Maximum number of colors that can be faded in one keyframe. More...
 

Enumerations

enum  fade_type_t { FADE_TYPE_STEP , FADE_TYPE_CUBIC }
 The type of fade to perform. More...
 
enum  fade_axis_t { FADE_AXIS_NONE = 0 , FADE_AXIS_HUE = (1U << 0) , FADE_AXIS_SAT = (1U << 1) , FADE_AXIS_VAL = (1U << 2) }
 The color axes/channels to fade over. More...
 

Functions

static bool keyframe_fade_render_frame (keyframe_base_t *const p_keyframe, timestep_t time, color_rgb_t *p_color_out)
 
static void keyframe_fade_render_init (keyframe_base_t *const p_keyframe, framerate_t framerate, color_rgb_t current_color)
 
static keyframe_base_t * keyframe_fade_clone (keyframe_base_t const *const p_keyframe)
 
static void blend_colors (color_hsv_t const *p_a, color_hsv_t const *p_b, fade_axis_t axis, float ratio, color_hsv_t *p_out)
 Blends two HSV colors based on a ratio between a to b. More...
 
static void cubic_bezier_calc (cubic_bezier_t const *const p_curve, float t, point_t *p_point)
 Calculates a point on a cubic bezier curve at interpolation index, t. More...
 
keyframe_base_t * keyframe_fade_parse (char *p_str)
 Parses a command string into a Fade Keyframe. More...
 
keyframe_base_t * keyframe_fade_ctor (keyframe_fade_t *p_fade)
 Initialize a Fade keyframe with the appropriate keyframe_base_t and state values. More...
 

Variables

static const keyframe_base_api_t keyframe_fade_api
 Fade keyframe API function pointers. More...
 
static const keyframe_fade_t keyframe_fade_init
 Default values for fade keyframe structs. More...
 
const cubic_bezier_t cb_linear = { { 0.0f, 0.0f }, { 1.0f, 1.0f } }
 Control points for linear fade. More...
 
const cubic_bezier_t cb_ease = { { 0.25f, 0.1f }, { 0.25f, 1.0f } }
 Control points for ease fade. More...
 
const cubic_bezier_t cb_ease_in = { { 0.42f, 0.0f }, { 1.0f, 1.0f } }
 Control points for ease-in fade. More...
 
const cubic_bezier_t cb_ease_out = { { 0.0f, 0.0f }, { 0.58f, 1.0f } }
 Control points for ease-out fade. More...
 
const cubic_bezier_t cb_ease_in_out = { { 0.42f, 0.0f }, { 0.58f, 1.0f } }
 Control points for ease-in-out fade. More...
 
const cubic_bezier_t cb_linear
 Control points for linear fade. More...
 
const cubic_bezier_t cb_ease
 Control points for ease fade. More...
 
const cubic_bezier_t cb_ease_in
 Control points for ease-in fade. More...
 
const cubic_bezier_t cb_ease_out
 Control points for ease-out fade. More...
 
const cubic_bezier_t cb_ease_in_out
 Control points for ease-in-out fade. More...
 

Detailed Description

Keyframe for transitioning between two or more colors.

Macro Definition Documentation

◆ KEYFRAME_FADE_COLORS_MAX_LENGTH

#define KEYFRAME_FADE_COLORS_MAX_LENGTH   (KEYFRAME_FADE_COLORS_INPUT_MAX_LENGTH + 1)

Maximum number of colors that can be faded in one keyframe.

Input + 1 to allow current color to be pushed to the top.

Enumeration Type Documentation

◆ fade_axis_t

The color axes/channels to fade over.

Enumerator
FADE_AXIS_NONE 

No axis require fading.

FADE_AXIS_HUE 

Fade is needed for the Hue axis.

FADE_AXIS_SAT 

Fade is needed for the Saturation axis.

FADE_AXIS_VAL 

Fade if needed for the Value axis.

◆ fade_type_t

The type of fade to perform.

Enumerator
FADE_TYPE_STEP 

Colors are immediately transitioned.

FADE_TYPE_CUBIC 

The transition curve is applied between every pair of colors.

Function Documentation

◆ blend_colors()

static void blend_colors ( color_hsv_t const *  p_a,
color_hsv_t const *  p_b,
fade_axis_t  axis,
float  ratio,
color_hsv_t p_out 
)
static

Blends two HSV colors based on a ratio between a to b.

Parameters
[in]p_aPointer to color a (ratio = 0).
[in]p_bPointer to color b (ratio = 1).
axisThe axes to blend across.
ratioThe ratio between color a and color b.
[out]p_outPointer to store the blended color.

◆ cubic_bezier_calc()

static void cubic_bezier_calc ( cubic_bezier_t const *const  p_curve,
float  t,
point_t p_point 
)
static

Calculates a point on a cubic bezier curve at interpolation index, t.

This function assumes start, \( P_0 \), and end, \( P_3 \), points of \( (0,0) \) and \( (1,1) \) respectively. The equation for the bezier curve is

\[ \vec{B}(t) = (1-t)^3 \vec{P}_0 + 3 (1-t)^2 t \vec{P}_1 + 3 (1-t) t^2 \vec{P}_2 + t^3 \vec{P}_3, \quad 0 \le t \le 1 \]

or simplified using the assumptions for \( P_0 \) and \( P_3 \)

\[ \vec{B}(t) = 3 (1-t)^2 t \vec{P}_1 + 3 (1-t) t^2 \vec{P}_2 + t^3, \quad 0 \le t \le 1 \]

Parameters
[in]p_curvePointer to the bezier control points.
tInterpolation index at which to calculate a point on the curve; 0 <= t <= 1.
[out]p_pointPointer to store the calculated point.

◆ keyframe_fade_ctor()

keyframe_base_t * keyframe_fade_ctor ( keyframe_fade_t p_fade)

Initialize a Fade keyframe with the appropriate keyframe_base_t and state values.

Parameters
[in]p_fadePointer to the fade keyframe to construct, or NULL to allocate a new one.
Returns
Pointer to the keyframe base portion of the fade keyframe.

◆ keyframe_fade_parse()

keyframe_base_t * keyframe_fade_parse ( char *  p_str)

Parses a command string into a Fade Keyframe.

Parameters
[in]p_strPointer to the command string.
Returns
Pointer to the parsed keyframe or NULL on error.

Variable Documentation

◆ cb_ease [1/2]

const cubic_bezier_t cb_ease = { { 0.25f, 0.1f }, { 0.25f, 1.0f } }

Control points for ease fade.

Quickly fades from the start value, then transitions slower to the end value.

◆ cb_ease [2/2]

const cubic_bezier_t cb_ease
extern

Control points for ease fade.

Quickly fades from the start value, then transitions slower to the end value.

◆ cb_ease_in [1/2]

const cubic_bezier_t cb_ease_in = { { 0.42f, 0.0f }, { 1.0f, 1.0f } }

Control points for ease-in fade.

Slow fade at the start then quickly fades to the end value.

◆ cb_ease_in [2/2]

const cubic_bezier_t cb_ease_in
extern

Control points for ease-in fade.

Slow fade at the start then quickly fades to the end value.

◆ cb_ease_in_out [1/2]

const cubic_bezier_t cb_ease_in_out = { { 0.42f, 0.0f }, { 0.58f, 1.0f } }

Control points for ease-in-out fade.

Quickly transitions from the start to the end; faster than normal ease.

◆ cb_ease_in_out [2/2]

const cubic_bezier_t cb_ease_in_out
extern

Control points for ease-in-out fade.

Quickly transitions from the start to the end; faster than normal ease.

◆ cb_ease_out [1/2]

const cubic_bezier_t cb_ease_out = { { 0.0f, 0.0f }, { 0.58f, 1.0f } }

Control points for ease-out fade.

Quickly fades from the start value then slowly fades to the end value.

◆ cb_ease_out [2/2]

const cubic_bezier_t cb_ease_out
extern

Control points for ease-out fade.

Quickly fades from the start value then slowly fades to the end value.

◆ cb_linear [1/2]

const cubic_bezier_t cb_linear = { { 0.0f, 0.0f }, { 1.0f, 1.0f } }

Control points for linear fade.

Fades linearly, in equal steps, between the start and end values.

◆ cb_linear [2/2]

const cubic_bezier_t cb_linear
extern

Control points for linear fade.

Fades linearly, in equal steps, between the start and end values.

◆ keyframe_fade_api

const keyframe_base_api_t keyframe_fade_api
static
Initial value:
=
{
.render_frame = keyframe_fade_render_frame,
.render_init = keyframe_fade_render_init,
.clone = keyframe_fade_clone,
}

Fade keyframe API function pointers.

◆ keyframe_fade_init

const keyframe_fade_t keyframe_fade_init
static
Initial value:
=
{
.base = { .p_api = &keyframe_fade_api },
.args =
{
.colors_len = 0,
.push_current = false,
.fade_type = FADE_TYPE_CUBIC,
.curve = { { 0.0f, 0.0f }, { 1.0f, 1.0f } },
.period = 1
}
}
static const keyframe_base_api_t keyframe_fade_api
Fade keyframe API function pointers.
Definition: keyframe_fade.c:25
@ FADE_TYPE_CUBIC
The transition curve is applied between every pair of colors.
Definition: keyframe_fade.h:34

Default values for fade keyframe structs.