knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

library(colourmebad)
set.seed(1)

colourmebad

colourmebad provides some tools for finding pronounceable approximations to hex colours.

These tools will be handy if you ever have to memorise a set of hex colours, or would like to impress people with your recall of a good colour palette as a party trick. In summary - no one needs these tools.

This package was inspired by mdsumner's hexwords package.

What's in the box

Installation

You can install from GitHub with:

# install.package('remotes')
remotes::install_github('coolbutuseless/colourmebad')

Hex colours which are dictionary words

library(colourmebad)

colour_words
colourmebad::colours_to_words(colour_words)

colourmebad::show_palette(colour_words)

Hex colours which are dictionary words if you allow for some digit-letter subsitutions

In the great tradition of "hacker speak" and customised number plates for cars, digits can be used in place of letters if they look similar enough.

The default substitutions this package employs:

cols <- sample(colour_words_with_substitutions, 25)
cols

colourmebad::colours_to_words(cols)
colourmebad::show_palette(cols)

Hex colours which are probably nonsense words but may be pronounceable

cols <- sample(nonsense_words, 25)
cols

colourmebad::colours_to_words(cols)
colourmebad::show_palette(cols)

Creating a pronounceable palette similar to a reference palette

ref <- RColorBrewer::brewer.pal(8, 'Dark2')

colourmebad::show_palette(ref, labels = ref, title = "Reference Palette")
pronounceable <- colourmebad::find_best_colour_match(ref, colour_words_with_substitutions)
colourmebad::compare_palettes(ref, pronounceable, "ColorBrewer Dark2", "Words with digit/letter substitutions")

Creating a pronounceable nonsense palette similar to a reference palette

pronounceable <- colourmebad::find_best_colour_match(ref, nonsense_words)
colourmebad::compare_palettes(ref, pronounceable, "ColorBrewer Dark2", "Nonsense words")

Creating a pronounceable Spanish palette similar to a reference palette

# http://ftp.icm.edu.pl/packages/wordlists/spanish/
spanish_words_with_substitutions <- system('grep -i -E "^[abcdeflsotgz]{6}$" ./working/spanish.txt', intern = TRUE)
cols <- colourmebad::words_to_colours(spanish_words_with_substitutions)
pronounceable_spanish <- colourmebad::find_best_colour_match(ref, cols)
colourmebad::compare_palettes(ref, pronounceable_spanish, "ColorBrewer Dark2", "Spanish words")
library(grid)
library(ingrid)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Parameters for a hex
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
r     <- 100
theta <- seq(30, 360, 60) * pi/180 
x     <- r * cos(theta)
y     <- r * sin(theta)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# a hex polygon
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hex <- polygon_grob(x, y, fill = 'black')

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create an image maskeed by the hex
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jpg <- jpeg::readJPEG("./man/figures/cmb.jpg")
image <- raster_grob(
  image  = jpg, 
  x      = .mm(0),
  y      = .mm(6),
  width  = .mm(1.8 * r), 
  height = .mm(1.8 * r),
  mask   = hex
)


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Position text
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# text <- text_grob(
#   label      = 'ingrid',
#   x          =  0.25 * r,
#   y          = -0.75 * r, 
#   rot        = 30,
#   just       = 0,
#   col        = 'white', 
#   fontfamily = 'courier',
#   cex        = 4
# )

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Draw the objects
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grid::grid.newpage()
grid::grid.draw(image)
# grid::grid.draw(text)


png("./man/figures/logo.png", type = 'cairo', width = 600, height = 600, bg = 'transparent')
grid::grid.newpage()
grid::grid.draw(hex)
grid::grid.draw(image)
# grid::grid.draw(text)
invisible(dev.off())

Related Software

Acknowledgements



coolbutuseless/colourmebad documentation built on Dec. 19, 2021, 6:03 p.m.