Package 'dehex'

Title: Learn to Roughly Assess Colour Hex Codes By Eye
Description: Follow David DeSandro's method to quickly generate a rough colour name (e.g. 'light washed yellow') by looking only at its hex code (e.g. #F2D359). Contains standalone functions and a Shiny app for learning the process interactively.
Authors: Matt Dray [aut, cre]
Maintainer: Matt Dray <[email protected]>
License: MIT + file LICENSE
Version: 0.1.2
Built: 2024-10-23 02:58:17 UTC
Source: https://github.com/matt-dray/dehex

Help Index


A Shiny App Walkthrough to Read Colour Hex Codes

Description

Rather than manually typing functions of dehex into your console, you can instead run this Shiny app to be guided through the process of learning to read a random colour hex code.

Usage

dh_app()

Value

Opens a Shiny app.

Examples

## Not run: dh_app()

Print a Hex Shortcode as an RGB graph

Description

Takes a three-character hex colour shortcode and prints to the console a bar chart of the red (R), green (G) and blue (B) values using unicode blocks. This provides a quick visual assessment of the relative amounts of each colour expressed by the hex shortcode.

Usage

dh_graph(
  hex_short,
  text = NULL,
  adorn_h = TRUE,
  adorn_s = TRUE,
  adorn_l = TRUE,
  crayon = TRUE
)

Arguments

hex_short

Character. A valid hex-colour shortcode starting with a hash mark (#) and followed by three alphanumeric characters, which must take the values 0 to 9 or A to F (case insensitive).

text

Character. An optional string to place above the plot. If NULL (default), then the shortcode will be automatically selected.

adorn_h

Logical. Add an optional value showing the relative rank of the RGB values (i.e. am indicator of hue)? A visual aid.

adorn_s

Logical. Add an optional bar showing where the range of the RGB values falls (i.e. am indicator of saturation)? A visual aid.

adorn_l

Logical. Add an optional bar showing where the mean of the RGB values falls (i.e. am indicator of lightness)? A visual aid.

crayon

Logical. Do you want to print to the console in colour, using the crayon package?

Details

The amount of red (R), green (G) and blue (B) is calculated on the basis that hex shortcodes contain one character for each colour. Since they're hexadecimal, they can take one of 16 possible values: 0 to 9 and then alphabetic characters from A to F (i.e. 10 to 15). That means that a shortcode of '#18F' has relative RGB values of 1, 8 and 16.

Value

Nothing. Prints to the console with cat() a bar chart.

Examples

dh_graph("#D83")

Print RGB Bar Graphs as Guides for Hue, Saturation and Light

Description

Print bar charts of RGB values that represent simplified groupings of hue, saturation or lightness levels in the HSL system. Intended for use as a reference to assess which RGB profiles most closely represents a user's hex shortcode.

Usage

dh_guide(type = c("H", "S", "L"), crayon = TRUE)

Arguments

type

Character. Which of hue ('H'), saturation ('S') or light ('L') that you want to print the guide for.

crayon

Logical. Do you want to print to the console in colour, using the crayon package?

Details

The hue guide prints guides for the primary (red, green, blue), secondary (yellow, cyan, magenta) and tertiary (orange, chartreuse, aquamarine, azure, violet, rose) hues. For saturation, the guide contains 'washed' (i.e. the largest range in RGB values), muted, and grey (i.e. no difference between RGB values). In the lightness guide they're 'light' (i.e.high mean value of RGB), 'middle', and 'dark' (i.e. small range in RGB values).

Value

Nothing. Prints bar charts of RGB values to the console, made with unicode blocks.

Examples

dh_guide("L")

Generate a Random Hex Colour Code

Description

The purpose of {dehex} is to train how to 'read' the colour from a hex code. This function generates a random hex code for you so you can test your skills.

Usage

dh_random(shorten = FALSE)

Arguments

shorten

Logical. Shorten six-character hex colour code to three characters? The three-character hex code is what is used to interpret the colour in the {dehex} 'training' context.

Value

Character string of length one. A three- or six-character hex code preceded by a hash mark, '#'.

Examples

dh_random(TRUE)

Convert a Full Hex Code to Shorthand Code

Description

Takes a hex code like '#C0FFEE' and simplifies to '#CFE' (i.e. the first character from each character pair).

Usage

dh_shorten(hex_code)

Arguments

hex_code

Character. A valid hex colour code starting with a hash mark (#). Characters must take the values 0 to 9 or A to F (case insensitive).

Value

Character. A shortened hex colour code: a hash mark followed by three characters (0 to 9, A to F).

Examples

dh_shorten("#C0FFEE")

Get a Name for a Hex Code With Optional Diagnostic Plots and Swatch

Description

Convert a colour hex code to an English string that roughly describes its colour in terms of hue, saturation and lightness, like 'dark saturated azure'. Optionally plot a block with the colour that the hex code encodes. Optionally print to the console the hue, saturation and lightness graphs that best approximate that hex code.

Usage

dh_solve(hex_code, swatch = FALSE, graphs = FALSE, crayon = TRUE)

Arguments

hex_code

Character. A valid hex colour code starting with a hash mark (#). Characters must take the values 0 to 9 or A to F (case insensitive).

swatch

Logical. Print to a graphical device a plot of the colour represented by (three-digit) hex code? Defaults to FALSE.

graphs

Logical. Do you want to print the result and associated hue, saturation and lightness bar charts to the console? Defaults to FALSE.

crayon

Logical. Do you want to print to the console in colour, using the crayon package?

Value

A character string. Optionally some console output and a plot.

Examples

dh_solve("#08F", graphs = FALSE, swatch = FALSE)

Plot the Colour of a Short Hex Code

Description

Check the colour of an input hex colour code by plotting it.

Usage

dh_swatch(hex_code)

Arguments

hex_code

Character. A valid hex colour code starting with a hash mark (#). Characters must take the values 0 to 9 or A to F (case insensitive).

Value

A plot.

Examples

dh_swatch("#F14362")