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 |
Interpolate (non-linearly) between two colors
seq_color( col1, col2, n = 100, type = "cubic", direction = "in-out", colorspace = "hcl" )
seq_color( col1, col2, n = 100, type = "cubic", direction = "in-out", colorspace = "hcl" )
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 |
character vector containing a color sequence
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))
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.
seq_ease(x1 = 0, x2 = 1, n = 100, type = "cubic", direction = "in-out")
seq_ease(x1 = 0, x2 = 1, n = 100, type = "cubic", direction = "in-out")
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' |
Numeric vector of length n
x <- seq_ease(x1 = 0, x2 = 1, n = 20, type = 'cubic', direction = 'in-out') x plot(x)
x <- seq_ease(x1 = 0, x2 = 1, n = 20, type = 'cubic', direction = 'in-out') x plot(x)