NeoFaker.Color (neo_faker v0.11.0)

View Source

Functions for generating random colors.

This module provides utilities to generate random colors in various formats.

Summary

Functions

Generates a CMYK color.

Generates a HEX color.

Generates an HSL color.

Generates an HSLA color.

Generates a keyword color.

Generates an RGB color.

Generates an RGBA color.

Functions

cmyk(opts \\ [])

(since 0.8.0)
@spec cmyk(Keyword.t()) :: tuple() | String.t()

Generates a CMYK color.

Returns a CMYK color. If no options are provided, the color is returned in tuple format.

Options

  • :format - Specifies the output format.

The values for :format can be:

  • nil - Returns the color in tuple format (default).
  • :w3c - Returns the color in W3C format.

Examples

iex> NeoFaker.Color.cmyk()
{0, 25, 50, 100}

iex> NeoFaker.Color.cmyk(format: :w3c)
"cmyk(0%, 25%, 50%, 100%)"

hex(opts \\ [])

(since 0.8.0)
@spec hex(Keyword.t()) :: String.t()

Generates a HEX color.

Returns a HEX color. If no options are provided, the color is returned in six-digit format.

Options

  • :format - Specifies the output format.

The values for :format can be:

  • :six_digit - Returns the color in six-digit format (default).
  • :three_digit - Returns the color in three-digit format.
  • :four_digit - Returns the color in four-digit format.
  • :eight_digit - Returns the color in eight-digit format.

Examples

iex> NeoFaker.Color.hex()
"#613583"

iex> NeoFaker.Color.hex(format: :three_digit)
"#365"

hsl(opts \\ [])

(since 0.8.0)
@spec hsl(Keyword.t()) :: tuple() | String.t()

Generates an HSL color.

This function behaves the same way as cmyk/1. See cmyk/1 for more details.

hsla(opts \\ [])

(since 0.8.0)
@spec hsla(Keyword.t()) :: tuple() | String.t()

Generates an HSLA color.

This function behaves the same way as cmyk/1. See cmyk/1 for more details.

keyword(opts \\ [])

(since 0.8.0)
@spec keyword(Keyword.t()) :: String.t()

Generates a keyword color.

Returns a keyword color. If no options are provided, all category colors are returned.

Options

  • :category - Specifies the category of keyword colors.
  • :locale - Specifies the locale to use.

The values for :category can be:

  • :all - Returns all keyword colors (default).
  • :basic - Returns basic keyword colors.
  • :extended - Returns extended keyword colors.

The values for :locale can be:

  • nil - Uses the default locale :default.
  • :id_id - Uses the Indonesian locale, for example.

Examples

iex> NeoFaker.Color.keyword()
"blueviolet"

iex> NeoFaker.Color.keyword(category: :basic)
"purple"

iex> NeoFaker.Color.keyword(locale: :id_id)
"ungu"

rgb(opts \\ [])

(since 0.8.0)
@spec rgb(Keyword.t()) :: tuple() | String.t()

Generates an RGB color.

This function behaves the same way as cmyk/1. See cmyk/1 for more details.

rgba(opts \\ [])

(since 0.8.0)
@spec rgba(Keyword.t()) :: tuple() | String.t()

Generates an RGBA color.

This function behaves the same way as cmyk/1. See cmyk/1 for more details.