fill_noise() builds a grid::pattern() fill value from a rasterised
simplex/fractal noise field, using the same noise machinery as
shape_blob()'s wobbly outline (ambient::fracture() /
ambient::gen_simplex() / ambient::fbm(), with matching frequency,
octaves, and seed arguments), so a noise-filled shape and a
noise-wobbled outline share one visual vocabulary.
Usage
fill_noise(
color = "black",
spacing = 0.5,
aspect = NULL,
resolution = 32L,
alpha = 1,
frequency = 1,
octaves = 2L,
seed = 1L,
extend = "repeat"
)Arguments
- color
One or more fill colours. A single colour (the default) fades in opacity from fully transparent to
alpha, exactly as before this argument accepted a vector. Two or more colours instead blend across agrDevices::colorRamp()built from them, driven by the noise value, withalphaapplied as a flat opacity across the whole fill (see the internalnoise_to_pixels()helper). Default"black".- spacing
Baseline tile size, as a fraction of the target's bounding box. Must be a positive number. Default
0.5.- aspect
Width-to-height ratio of the target polygon's bounding box. Must be a positive number, or
NULL(the default) to resolve it automatically from the real target's own bounding-box aspect ratio atdraw()time – see the fill class. Passing a fixed number instead computes the pattern once, immediately, against that value only.- resolution
Raster resolution (pixels per tile edge). Must be a positive integer of at least
2L. Default32L.- alpha
Opacity. For a single
color, the maximum opacity at the noise field's peak; for two or more, a flat opacity applied uniformly. Must be a number in(0, 1]. Default1.- frequency
Noise frequency, as in
shape_blob(). Must be non-negative. Default1.- octaves
Number of noise octaves, as in
shape_blob(). Must be a positive integer. Default2L.- seed
Integer seed for the noise field, as in
shape_blob(). Default1L.- extend
Passed to
grid::pattern(). Default"repeat".
Value
A pattern object as returned by grid::pattern(), suitable for
use as the fill argument to grid::gpar().
Details
Noise is rendered as varying opacity of a single color, from fully
transparent at the noise field's minimum to alpha at its maximum –
a mottled, cloud-like texture rather than a hard-edged one.
A raster tile has no baked-in direction the way a hatch line does, so
fill_hatch()'s tile-edge "dashing" problem doesn't apply directly, but
an ordinary noise field still isn't periodic, and grid::pattern()'s
extend = "repeat" will visibly seam wherever one tile edge fails to
match the next. fill_noise() avoids this by sampling the noise on a
torus: each raster pixel's (u, v) tile coordinate is mapped onto a pair
of circles (ambient::gen_simplex()'s 4 dimensions, x/y for u and
z/t for v) rather than sampled directly, so the field is
mathematically periodic in both directions and tiles with no visible
seam, at the cost of the noise "wrapping around" within each tile rather
than varying smoothly across a larger area.
In practice, a very faint seam can still be visible at tile boundaries on
some devices, even though the underlying field is exactly periodic; this
appears to be an artifact of how the graphics device samples a repeated
raster tile (it persists regardless of interpolate and doesn't improve
with higher resolution), not a flaw in the noise field itself, and is
far subtler than the tile-edge mismatch fill_hatch() has to actively
avoid.
Examples
draw(shape_circle(fill = fill_noise(seed = 8843L)))
# higher frequency/octaves give finer-grained texture
draw(shape_circle(
fill = fill_noise(frequency = 4, octaves = 4L, seed = 8843L)
))
# a lower alpha lets the shape's own outline/background show through more
draw(shape_circle(
fill = fill_noise(color = "steelblue", alpha = 0.5, seed = 8843L)
))
# two or more colours blend across the field instead of fading to transparent
draw(shape_circle(
fill = fill_noise(color = c("steelblue", "white", "tomato"), seed = 8843L)
))