Skip to contents

Generates n colours by taking successive random steps through RGB space, starting at base, reflecting back into range at the [0, 1] boundary of each channel rather than clamping – so a channel that would overshoot bounces back instead of flattening out at the boundary for the rest of the walk. This gives a sequence of related but organically drifting colours, in contrast to palette_harmony()'s fixed geometric relationships or palette_cosine()'s periodic formula.

Usage

palette_walk(n, base = NULL, step = 0.08, seed = 1L)

Arguments

n

A single positive whole number: the number of colours to generate.

base

NULL (the default) or a single colour to start the walk at. NULL starts from a uniform-random colour instead.

step

A single positive number controlling the standard deviation of each channel's random step between successive colours – larger values wander further/faster.

seed

A single whole number seeding the random walk, so the same seed always produces the same palette.

Value

A character vector of n hex colour strings.

Examples

palette_walk(n = 10, base = "seagreen", seed = 4187)
#>  [1] "#2E8B57" "#018261" "#108570" "#068A78" "#01A47E" "#148A73" "#2E9B92"
#>  [8] "#0CA179" "#11BE83" "#26DD81"
palette_walk(n = 10, step = 0.2, seed = 4187)
#>  [1] "#04B453" "#0E9589" "#3AA1DE" "#2588B3" "#1D758F" "#1485A3" "#553D50"
#>  [8] "#3433B4" "#7B28B8" "#FA0142"
draw(effect_swatch(color = palette_walk(n = 10, base = "seagreen", seed = 4187)))