Skip to content

Commit

Permalink
Rename Effect back to Animation
Browse files Browse the repository at this point in the history
  • Loading branch information
doughsay committed Jul 5, 2020
1 parent e003fe4 commit c17128d
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 130 deletions.
52 changes: 26 additions & 26 deletions lib/rgb_matrix/effect.ex → lib/rgb_matrix/animation.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule RGBMatrix.Effect do
defmodule RGBMatrix.Animation do
alias Layout.LED

@callback new(leds :: list(LED.t()), config :: any) :: {render_in, any}
Expand All @@ -15,7 +15,7 @@ defmodule RGBMatrix.Effect do

defmacro __using__(_) do
quote do
@behaviour RGBMatrix.Effect
@behaviour RGBMatrix.Animation
end
end

Expand All @@ -30,7 +30,6 @@ defmodule RGBMatrix.Effect do
| __MODULE__.SolidColor
| __MODULE__.Breathing
| __MODULE__.SolidReactive
| __MODULE__.Splash

@doc """
Returns a list of the available types of animations.
Expand All @@ -45,44 +44,45 @@ defmodule RGBMatrix.Effect do
__MODULE__.RandomKeypresses,
__MODULE__.SolidColor,
__MODULE__.Breathing,
__MODULE__.SolidReactive,
__MODULE__.Splash
__MODULE__.SolidReactive
]
end

@doc """
Returns an effect's initial state.
Returns an animation's initial state.
"""
@spec new(effect_type :: type, leds :: list(LED.t())) :: {render_in, t}
def new(effect_type, leds) do
config_module = Module.concat([effect_type, Config])
effect_config = config_module.new()
{render_in, effect_state} = effect_type.new(leds, effect_config)
@spec new(animation_type :: type, leds :: list(LED.t())) :: {render_in, t}
def new(animation_type, leds) do
config_module = Module.concat([animation_type, Config])
animation_config = config_module.new()
{render_in, animation_state} = animation_type.new(leds, animation_config)

effect = %__MODULE__{
type: effect_type,
config: effect_config,
state: effect_state
animation = %__MODULE__{
type: animation_type,
config: animation_config,
state: animation_state
}

{render_in, effect}
{render_in, animation}
end

@doc """
Returns the next state of an effect based on its current state.
Returns the next state of an animation based on its current state.
"""
@spec render(effect :: t) :: {list(RGBMatrix.any_color_model()), render_in, t}
def render(effect) do
{colors, render_in, effect_state} = effect.type.render(effect.state, effect.config)
{colors, render_in, %{effect | state: effect_state}}
@spec render(animation :: t) :: {list(RGBMatrix.any_color_model()), render_in, t}
def render(animation) do
{colors, render_in, animation_state} =
animation.type.render(animation.state, animation.config)

{colors, render_in, %{animation | state: animation_state}}
end

@doc """
Sends an interaction event to an effect.
Sends an interaction event to an animation.
"""
@spec interact(effect :: t, led :: LED.t()) :: {render_in, t}
def interact(effect, led) do
{render_in, effect_state} = effect.type.interact(effect.state, effect.config, led)
{render_in, %{effect | state: effect_state}}
@spec interact(animation :: t, led :: LED.t()) :: {render_in, t}
def interact(animation, led) do
{render_in, animation_state} = animation.type.interact(animation.state, animation.config, led)
{render_in, %{animation | state: animation_state}}
end
end
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
defmodule RGBMatrix.Effect.Breathing do
defmodule RGBMatrix.Animation.Breathing do
@moduledoc """
Single hue brightness cycling.
"""

alias Chameleon.HSV
alias RGBMatrix.Effect
alias RGBMatrix.Animation

use Effect
use Animation

defmodule Config do
use RGBMatrix.Effect.Config
use RGBMatrix.Animation.Config
end

defmodule State do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
defmodule RGBMatrix.Effect.Config do
defmodule RGBMatrix.Animation.Config do
@callback schema() :: keyword(any)
@callback new(%{optional(atom) => any}) :: struct
@callback update(struct, %{optional(atom) => any}) :: struct

@types %{
integer: RGBMatrix.Effect.Config.Integer,
option: RGBMatrix.Effect.Config.Option
integer: RGBMatrix.Animation.Config.Integer,
option: RGBMatrix.Animation.Config.Option
}

defmacro __using__(_) do
quote do
import RGBMatrix.Effect.Config
import RGBMatrix.Animation.Config

Module.register_attribute(__MODULE__, :fields,
accumulate: true,
persist: false
)

@before_compile RGBMatrix.Effect.Config
@before_compile RGBMatrix.Animation.Config
end
end

Expand All @@ -36,17 +36,17 @@ defmodule RGBMatrix.Effect.Config do
schema = Macro.escape(schema)

quote do
@behaviour RGBMatrix.Effect.Config
@behaviour RGBMatrix.Animation.Config

@enforce_keys unquote(keys)
defstruct unquote(keys)

@impl RGBMatrix.Effect.Config
@impl RGBMatrix.Animation.Config
def schema do
unquote(schema)
end

@impl RGBMatrix.Effect.Config
@impl RGBMatrix.Animation.Config
def new(params \\ %{}) do
schema()
|> Map.new(fn {key, %mod{} = type} ->
Expand All @@ -60,7 +60,7 @@ defmodule RGBMatrix.Effect.Config do
|> (&struct!(__MODULE__, &1)).()
end

@impl RGBMatrix.Effect.Config
@impl RGBMatrix.Animation.Config
def update(config, params) do
schema = schema()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule RGBMatrix.Effect.Config.Integer do
defmodule RGBMatrix.Animation.Config.Integer do
@enforce_keys [:default, :min, :max]
defstruct [:default, :min, :max, step: 1]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule RGBMatrix.Effect.Config.Option do
defmodule RGBMatrix.Animation.Config.Option do
@enforce_keys [:default, :options]
defstruct [:default, :options]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
defmodule RGBMatrix.Effect.CycleAll do
defmodule RGBMatrix.Animation.CycleAll do
@moduledoc """
Cycles the hue of all LEDs at the same time.
"""

alias Chameleon.HSV
alias RGBMatrix.Effect
alias RGBMatrix.Animation

use Effect
use Animation

import RGBMatrix.Utils, only: [mod: 2]

defmodule Config do
use RGBMatrix.Effect.Config
use RGBMatrix.Animation.Config
end

defmodule State do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
defmodule RGBMatrix.Effect.HueWave do
defmodule RGBMatrix.Animation.HueWave do
@moduledoc """
Creates a wave of shifting hue that moves across the matrix.
"""

alias Chameleon.HSV
alias Layout.LED
alias RGBMatrix.Effect
alias RGBMatrix.Animation

use Effect
use Animation

import RGBMatrix.Utils, only: [mod: 2]

defmodule Config do
use RGBMatrix.Effect.Config
use RGBMatrix.Animation.Config

@doc name: "Speed",
description: """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
defmodule RGBMatrix.Effect.Pinwheel do
defmodule RGBMatrix.Animation.Pinwheel do
@moduledoc """
Cycles hue in a pinwheel pattern.
"""

alias Chameleon.HSV
alias Layout.LED
alias RGBMatrix.Effect
alias RGBMatrix.Animation

use Effect
use Animation

import RGBMatrix.Utils, only: [mod: 2]

defmodule Config do
use RGBMatrix.Effect.Config
use RGBMatrix.Animation.Config
end

defmodule State do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
defmodule RGBMatrix.Effect.RandomKeypresses do
defmodule RGBMatrix.Animation.RandomKeypresses do
@moduledoc """
Changes every key pressed to a random color.
"""

alias Chameleon.HSV
alias RGBMatrix.Effect
alias RGBMatrix.Animation

use Effect
use Animation

defmodule Config do
use RGBMatrix.Effect.Config
use RGBMatrix.Animation.Config
end

defmodule State do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
defmodule RGBMatrix.Effect.RandomSolid do
defmodule RGBMatrix.Animation.RandomSolid do
@moduledoc """
A random solid color fills the entire matrix and changes every key-press.
"""

alias Chameleon.HSV
alias RGBMatrix.Effect
alias RGBMatrix.Animation

use Effect
use Animation

defmodule Config do
use RGBMatrix.Effect.Config
use RGBMatrix.Animation.Config
end

defmodule State do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
defmodule RGBMatrix.Effect.SolidColor do
defmodule RGBMatrix.Animation.SolidColor do
@moduledoc """
All LEDs are a solid color.
"""

alias Chameleon.HSV
alias RGBMatrix.Effect
alias RGBMatrix.Animation

use Effect
use Animation

defmodule Config do
use RGBMatrix.Effect.Config
use RGBMatrix.Animation.Config
end

defmodule State do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
defmodule RGBMatrix.Effect.SolidReactive do
defmodule RGBMatrix.Animation.SolidReactive do
@moduledoc """
Static single hue, pulses keys hit to shifted hue then fades to current hue.
"""

alias Chameleon.HSV
alias RGBMatrix.Effect
alias RGBMatrix.Animation

use Effect
use Animation

import RGBMatrix.Utils, only: [mod: 2]

defmodule Config do
use RGBMatrix.Effect.Config
use RGBMatrix.Animation.Config

@doc name: "Speed",
description: """
Expand Down
Loading

0 comments on commit c17128d

Please sign in to comment.