Skip to contents

R-CMD-check pkgdown CRAN status Codecov test coverage CRAN downloads CRAN downloads total License: MIT Lifecycle: experimental

syn_palette() is a generic: it derives the same syn_palette object from a prosody score, a character string, an audio Wave, or an image. That makes palettes interchangeable across sources.

From text

syn_palette("A warm and joyful golden afternoon.", lang = "en")
#> <syn_palette> - 5 colours, warm, from prosody_score
#> "#7F1C1A" background
#> "#9F5411" shadow
#> "#BC871E" mid
#> "#D3BB48" accent
#> "#E3F17E" highlight

From audio

Any tuneR::Wave works — including the audio synesthR itself generates. The palette’s temperature follows the spectral brightness of the sound (computed with base R, no extra dependency):

w <- tuneR::sine(660, duration = 8000, samp.rate = 8000, bit = 16, pcm = TRUE)
syn_palette(w)
#> <syn_palette> - 5 colours, cool, from audio
#> "#005C30" background
#> "#00846C" shadow
#> "#00ACA7" mid
#> "#00D5E3" accent
#> "#0DFEFF" highlight

From an image (optional)

The image method uses the optional magick package. It downsamples, clusters colours in Lab space, and orders them by luminance. It runs only when magick is installed:

img <- magick::image_blank(80, 80, color = "tomato")
syn_palette(img)
#> <syn_palette> - 3 colours, mixed, from image
#> "#474747" background
#> "#636363" shadow
#> "#FFFFFF" mid

If magick is not installed the method aborts with an informative message rather than failing the core workflow.

Turning a palette into a theme

pal <- syn_palette(syn_score(syn_read_text("Quiet grey morning by the sea.", lang = "en")))
th <- syn_theme(pal)
class(th)
#> [1] "theme"          "ggplot2::theme" "gg"             "S7_object"