Package 'displease'

Title: Numeric and Color Sequences with Non-Linear Interpolation
Description: When visualising changes between two values over time, a strict linear interpolation can look jarring and unnatural. By applying a non-linear easing to the transition, the motion between values can appear smoother and more natural. This package includes functions for applying such non-linear easings to colors and numeric values, and is useful where smooth animated movement and transitions are desired.
Authors: Mike Cheng [aut, cre, cph]
Maintainer: Mike Cheng <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2024-12-16 23:38:12 UTC
Source: CRAN

Help Index


Interpolate (non-linearly) between two colors

Description

Interpolate (non-linearly) between two colors

Usage

seq_color(
  col1,
  col2,
  n = 100,
  type = "cubic",
  direction = "in-out",
  colorspace = "hcl"
)

Arguments

col1, col2

the two colors to interpolate between

n

Number of steps for the transition (including the endpoints)

type

Type of motion easing. Default: 'cubic'. Valid values are are 'sine', 'quad', 'cubic', 'quart', 'quint', 'exp', 'circle', 'back', 'elastic', 'linear'.

direction

When should the easing apply? Default: "in-out". Valid values are 'in', 'out', in-out'. Default: 'in-out'

colorspace

Color space in which to do the interpolation. Default: 'hcl' Can be any colorspace understood by the farver package i.e. "cmy", "cmyk", "hsl", "hsb", "hsv", "lab" (CIE L*ab), "hunterlab" (Hunter Lab), "oklab", "lch" (CIE Lch(ab) / polarLAB), "luv", "rgb" (sRGB), "xyz", "yxy" (CIE xyY), "hcl" (CIE Lch(uv) / polarLuv), or "oklch" (Polar form of oklab). Note: Not all color spaces make sense for interpolation.

Value

character vector containing a color sequence

Examples

n <- 20
cols <- seq_color('red', 'blue', n = n, direction = 'in-out', colorspace = 'hcl')
cols
grid::grid.rect(x = seq(0, 0.95, length.out = n), width = 0.1, 
                gp = grid::gpar(fill = cols, col = NA))

Create a sequence interpolating between two values with the specified non-linear easing.

Description

Create a sequence interpolating between two values with the specified non-linear easing.

Usage

seq_ease(x1 = 0, x2 = 1, n = 100, type = "cubic", direction = "in-out")

Arguments

x1, x2

The start and end values of the sequence. Default: 0, 1

n

Number of steps for the transition (including the endpoints)

type

Type of motion easing. Default: 'cubic'. Valid values are are 'sine', 'quad', 'cubic', 'quart', 'quint', 'exp', 'circle', 'back', 'elastic', 'linear'.

direction

When should the easing apply? Default: "in-out". Valid values are 'in', 'out', in-out'. Default: 'in-out'

Value

Numeric vector of length n

Examples

x <- seq_ease(x1 = 0, x2 = 1, n = 20, type = 'cubic', direction = 'in-out')
x
plot(x)