grid.pattern_ambient()
draws noise patterns onto the graphic device powered by the ambient
package.
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
)
A grid grob object invisibly. If draw
is TRUE
then also draws to the graphic device as a side effect.
A numeric vector or unit object specifying x-locations of the pattern boundary.
A numeric vector or unit object specifying y-locations of the pattern boundary.
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.
Either cubic, perlin, simplex, value, white, or worley
Colour.
Second colour.
Determines the granularity of the features in the noise.
How should values between sampled points be calculated?
Either 'linear'
, 'hermite'
, or 'quintic'
(default), ranging from lowest
to highest quality.
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.
The number of noise layers used to create the fractal noise.
Ignored if fractal = 'none'
. Defaults to 3
.
The frequency multiplier between successive noise layers
when building fractal noise. Ignored if fractal = 'none'
. Defaults to 2
.
The relative strength between successive noise layers when
building fractal noise. Ignored if fractal = 'none'
. Defaults to 0.5
.
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.
The maximal pertubation distance from the
origin. Ignored if pertubation = 'none'
. Defaults to 1
.
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 by
distance_ind[1]
)
'distance2add'
Addition of the distance to the nth and mth closest point given in distance_ind
'distance2sub'
Substraction of the distance to the nth and mth closest point given in distance_ind
'distance2mul'
Multiplication of the distance to the nth and mth closest point given in distance_ind
'distance2div'
Division of the distance to the nth and mth closest point given in distance_ind
Reference to the nth and mth closest points that should
be used when calculating value
.
The maximum distance a point can move from its start position during sampling of cell points.
Assumed resolution (in pixels per graphic device inch) to use when creating array pattern.
Alpha (between 0 and 1) or NA
(default, preserves colors' alpha value).
A string indicating the default units to use if x
or y
are only given as numeric vectors.
A character identifier.
An object of class "gpar"
, typically the output
from a call to the function gpar
. This is basically
a list of graphical parameter settings.
A logical value indicating whether graphics output should be produced.
A Grid viewport object (or NULL).
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
.
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")
}
Run the code above in your browser using DataLab