grid.pattern_ambient()
draws noise patterns onto the graphic device powered by the ambient
package.
Usage
grid.pattern_ambient(
x = c(0, 0, 1, 1),
y = c(1, 0, 0, 1),
id = 1L,
...,
type = "simplex",
fill = gp$fill %||% "grey80",
fill2 = "#4169E1",
frequency = 0.01,
interpolator = "quintic",
fractal = switch(type, worley = "none", "fbm"),
octaves = 3,
lacunarity = 2,
gain = 0.5,
pertubation = "none",
pertubation_amplitude = 1,
value = "cell",
distance_ind = c(1, 2),
jitter = 0.45,
res = getOption("ggpattern_res", 72),
alpha = NA_real_,
default.units = "npc",
name = NULL,
gp = gpar(),
draw = TRUE,
vp = NULL
)
Arguments
- x
A numeric vector or unit object specifying x-locations of the pattern boundary.
- y
A numeric vector or unit object specifying y-locations of the pattern boundary.
- id
A numeric vector used to separate locations in x, y into multiple boundaries. All locations within the same
id
belong to the same boundary.- ...
Currently ignored.
- type
Either cubic, perlin, simplex, value, white, or worley
- fill
Colour.
- fill2
Second colour.
- frequency
Determines the granularity of the features in the noise.
- interpolator
How should values between sampled points be calculated? Either
'linear'
,'hermite'
, or'quintic'
(default), ranging from lowest to highest quality.- fractal
The fractal type to use. Either
'none'
,'fbm'
(default),'billow'
, or'rigid-multi'
. It is suggested that you experiment with the different types to get a feel for how they behaves.- octaves
The number of noise layers used to create the fractal noise. Ignored if
fractal = 'none'
. Defaults to3
.- lacunarity
The frequency multiplier between successive noise layers when building fractal noise. Ignored if
fractal = 'none'
. Defaults to2
.- gain
The relative strength between successive noise layers when building fractal noise. Ignored if
fractal = 'none'
. Defaults to0.5
.- pertubation
The pertubation to use. Either
'none'
(default),'normal'
, or'fractal'
. Defines the displacement (warping) of the noise, with'normal'
giving a smooth warping and'fractal'
giving a more eratic warping.- pertubation_amplitude
The maximal pertubation distance from the origin. Ignored if
pertubation = 'none'
. Defaults to1
.- value
The noise value to return. Either
'value'
(default) A random value associated with the closest point'distance'
The distance to the closest point'distance2'
The distance to the nth closest point (n given bydistance_ind[1]
)'distance2add'
Addition of the distance to the nth and mth closest point given indistance_ind
'distance2sub'
Substraction of the distance to the nth and mth closest point given indistance_ind
'distance2mul'
Multiplication of the distance to the nth and mth closest point given indistance_ind
'distance2div'
Division of the distance to the nth and mth closest point given indistance_ind
- distance_ind
Reference to the nth and mth closest points that should be used when calculating
value
.- jitter
The maximum distance a point can move from its start position during sampling of cell points.
- res
Assumed resolution (in pixels per graphic device inch) to use when creating array pattern.
- alpha
Alpha (between 0 and 1) or
NA
(default, preserves colors' alpha value).- default.units
A string indicating the default units to use if
x
ory
are only given as numeric vectors.- name
A character identifier.
- gp
An object of class
"gpar"
, typically the output from a call to the functiongpar
. This is basically a list of graphical parameter settings.- draw
A logical value indicating whether graphics output should be produced.
- vp
A Grid viewport object (or NULL).
Value
A grid grob object invisibly. If draw
is TRUE
then also draws to the graphic device as a side effect.
See also
For more information about the noise types please see the relevant ambient
documentation:
ambient::noise_cubic()
, ambient::noise_perlin()
, ambient::noise_simplex()
,
ambient::noise_value()
, ambient::noise_white()
, and ambient::noise_worley()
.
grid.pattern_plasma()
provides an alternative noise pattern that depends on magick
.
Examples
if (requireNamespace("ambient", quietly = TRUE)) {
x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
grid.pattern_ambient(x_hex, y_hex, fill = "green", fill2 = "blue")
}
if (requireNamespace("ambient")) {
grid::grid.newpage()
grid.pattern_ambient(x_hex, y_hex, fill = "green", fill2 = "blue", type = "cubic")
}