2.9 KiB
2.9 KiB
Hints
General
- Read about behaviours in the official Getting Started guide.
- Read about behaviours on elixirschool.com.
- Read about behaviours in the documentation.
- Read about
use
in the official Getting Started guide. - Read about
use
in the documentation.
1. Define the animation behaviour
- Use the
@callback
module attribute to define the desired functions. - Each callback must specify the function name, list of arguments (their types) and the return value (its type).
- Use the given custom types
dot
,opts
,error
, andframe_number
in the callbacks' definitions. - Refresh your knowledge of typespecs to help with defining callbacks.
2. Provide a default implementation of the init/1
callback
- Define a
__using__/1
macro in theDancingDots.Animation
module. - The macros' argument can be ignored.
- The macro must return a quoted expression.
- In the quoted expression, use
@behaviour
so that callinguse DancingDots.Animation
setsDancingDots.Animation
as the using module's behaviour. - In the quoted expression, implement the
init/1
function. - The default implementation of the
init/1
function should wrap the givenopts
argument in:ok
tuple. - There is a macro that can mark a function as overridable.
3. Implement the Flicker
animation
- Make use of
DancingDots.Animation
__using__/1
macro by calling this one special macro in theDancingDots.Flicker
module. - You do not need to implement the
init/1
function. Its default implementation is enough. - You need to implement the
handle_frame/3
function. - To detect "every 4th frame", you can check if the remainder when dividing it by 4 is equal to 0.
4. Implement the Zoom
animation
- Make use of
DancingDots.Animation
__using__/1
macro by calling this one special macro in theDancingDots.Zoom
module. - You need to implement both the
init/1
function and thehandle_frame/3
function. - Use the
Keyword
module to work with the options keyword list. - There is a built-in guard for checking if a value is a number.