Class Animation

Inheritance Relationships

Derived Types

Class Documentation

class Animation

Subclassed by PixelMaestro::BlinkAnimation, PixelMaestro::CycleAnimation, PixelMaestro::FireAnimation, PixelMaestro::LightningAnimation, PixelMaestro::MandelbrotAnimation, PixelMaestro::PlasmaAnimation, PixelMaestro::RadialAnimation, PixelMaestro::RandomAnimation, PixelMaestro::SolidAnimation, PixelMaestro::SparkleAnimation, PixelMaestro::VUAnimation, PixelMaestro::WaveAnimation

Public Types

enum Orientation

The orientation of the animation. Does not affect animations that don’t have a specific direction (e.g. CycleAnimation).

Values:

Horizontal
Vertical
HorizontalFlipped
VerticalFlipped

Public Functions

Animation(Section &section)

Constructor. Initializes the timer and map.

Parameters
  • section: The Section that this animation will render in.

~Animation()
Point &get_center() const

Returns the Animation’s center.

Return

Animation’s center.

uint8_t get_cycle_index() const

Returns the current cycle index.

Return

Cycle index.

bool get_fade() const

Returns whether the animation is fading.

Return

True if fading.

Animation::Orientation get_orientation() const

Returns the animation’s orientation.

Return

Animation’s orientation

Palette *get_palette() const

Returns the color palette.

Return

Color palette.

bool get_reverse() const

Returns whether the animation is running in reverse.

Return

True if running in reverse.

Section &get_section() const

Returns the Animation’s parent Section.

Return

Parent Section.

AnimationTimer *get_timer() const

Returns the animation’s timer.

Return

Animation timer.

AnimationType get_type() const

Returns the type of Animation.

Return

Animation type.

virtual void map() = 0
void rebuild_map()

Regenerates the color-to-pixel map.

void set_cycle_index(uint8_t index)

Sets the cycle index to the specified index.

Parameters
  • index: New cycle index.

void set_fade(bool fade)

Toggles fading the animation.

Parameters
  • fade: If true, fade between cycles.

void set_map_color_index(uint16_t x, uint16_t y, uint8_t color_index)

Assigns the specified Pixel to the specified color.

Parameters
  • x: Pixel’s x coordinate.

  • y: Pixel’s y coordinate.

  • color_index: Index of the color to set.

void set_center(uint16_t x, uint16_t y)

Sets the center of the Animation. Only applies to certain Animations.

Parameters
  • x: Center along the x axis.

  • y: Center along the y axis.

void set_orientation(Orientation orientation)

Sets the animation’s orientation.

Parameters
  • orientation: New orientation.

void set_palette(Palette &palette)

Sets a new color palette.

Parameters

void set_reverse(bool reverse)

Sets whether to run the animation in reverse.

Parameters
  • reverse: If true, run in reverse.

AnimationTimer &set_timer(uint16_t speed, uint16_t delay = 0)

Sets the amount of time between animation updates.

Parameters
  • speed: Amount of time (in milliseconds) between animation cycles.

  • delay: Amount of time (in milliseconds) to wait before starting an animation cycle.

bool update(const uint32_t &current_time)

Updates the animation. This checks to see if the animation should update, then calls the derived class’s update method. Finally, it renders the mapped color to each Pixel.

Return

True if the update was processed.

Parameters
  • current_time: The current runtime.

Protected Functions

virtual void update() = 0
void update_cycle(uint8_t min, uint8_t max)

Incremnets the current animation cycle. If reverse_animation_ is true, this decrements the cycle, moving the animation backwards. If the animation reaches the end of its cycle, it will jump back (or forward) to the start (or end).

Parameters
  • min: The minimum possible value of cycle_index_.

  • max: The maximum possible value of cycle_index_.

Protected Attributes

Point center_

The center of the Animation.

uint8_t cycle_index_ = 0

The current stage in the animation cycle. Defaults to 0.

Point dimensions_

Stores the current grid size.

bool fade_ = true

Whether to fade between cycles. Defaults to true.

bool initialized_ = false

False until the Animation has been fully allocated and mapped. Created for set_center().

uint8_t **map_ = nullptr

Mapping of color palette indices to Pixels. Note: 255 is reserved for the color black.

Orientation orientation_ = Orientation::Horizontal

The orientation of the animation. Defaults to HORIZONTAL.

Palette *palette_ = nullptr

Color palette used in the animation.

bool reverse_ = false

Whether to animate in reverse. Defaults to false.

Section &section_

The Animation’s parent Section.

AnimationTimer *timer_ = nullptr

The Animation’s timer. This is a pointer instead of a local object because we must initialize it after the Animation.

AnimationType type_ = AnimationType::Solid

The type of Animation. Gets set in the derived class’ constructor.