Fledex.Color.Names.Interface behaviour (fledex v0.7.0)
View SourceThis module defines the standard interface (behaviour) for color names modules which they should implement.
The easiest way to generate a color names module is probably by reading in a csv file
with the definitions with the help of Fledex.Color.Names.ModuleGenerator
Fledex has an extensive set of predefined colors from:
Fledex.Color.Names.Wikifrom Wikipedia - List of colors A-F, Wikipedia - List of colors G-M, Wikipedia - List of colors N-ZFledex.Color.Names.CSSfrom W3C - CSS colorsFledex.Color.Names.SVGfrom W3C - SVG colorsFledex.Color.Names.RALfrom Wikipedia - List of RAL colors
The behaviour only defines a very small set of functions, but it is expected that each color is reachable through a function with the name of the color. For example, you can
retrieve the information for the color :almond by calling the function with the same
name, i.e. almond/1.
The additional parameter determines which additional information should be provided. Each color module can define it's own set of parameters (except :all, :hex, and :name that are mandatory), but the classical options are:
:all: This retrieves the full data set:descriptive_name: a string with name (from this the Atom is derived):hex(default): This is the same asalmond/0:hsl: This retrieves an HSL struct, i.e.Fledex.Color.HSL:hsv: This retrieves an HSV struct, i.e.Fledex.Color.HSV:index: The index of this color in the list of all colors:rgb: This retrieves an RGB struct, i.e.{r, g, b}:source: Information where the color comes from, see Wikipedia for more details:module: to get more information where the color is actually implemented. The function might return:unknown
And finally every color exists also in a version that allows you to add it to a
Fledex.Leds sequence. Either as next led (almond/1) or with a specified offset
(almond/2). The latter has no extra documentation, because it wouldn't add any real
value, but would clutter the doc. Here an example spec:
@spec almond(leds :: Fledex.Leds.t, offset :: non_neg_integer) :: Fledex.Leds.tSome additional functions exist for retrieving all colors, all color names,
and info about an atom color. Thus, you can get the same information for
almond() by calling info(:almond, :hex)
Summary
Guards
Check whether the atom is a valid color name
Callbacks
Get all the data about the predefined colors
Retrieve information about the color with the given name
Get a list of all the predefined color (atom) names.
Guards
Callbacks
@callback colors() :: [Fledex.Color.Names.Types.color_struct_t()]
Get all the data about the predefined colors
@callback info(name :: atom(), :index) :: nil | integer()
@callback info(name :: atom(), :name) :: nil | Fledex.Color.Names.Types.color_name_t()
@callback info(name :: atom(), :descriptive_name) :: nil | String.t()
@callback info(name :: atom(), :hex) :: nil | Fledex.Color.Types.colorint()
@callback info(name :: atom(), :rgb) :: nil | Fledex.Color.Types.rgb()
@callback info(name :: atom(), :hsl) :: nil | Fledex.Color.Types.hsl()
@callback info(name :: atom(), :hsv) :: nil | Fledex.Color.Types.hsv()
@callback info(name :: atom(), :source) :: nil | String.t()
@callback info(name :: atom(), :module) :: nil | module()
@callback info(name :: atom(), :all) :: nil | Fledex.Color.Names.Types.color_vals_t()
@callback info(name :: atom(), what :: atom()) :: any()
Retrieve information about the color with the given name
@callback names() :: [atom()]
Get a list of all the predefined color (atom) names.
The name can be used to either retrieve the info by calling info/2 or by calling the function with that
name (see also the description at the top and take a look at this example
livebook)