trans wraps a 3x3 homogeneous-coordinates affine transformation
matrix. It is not usually constructed directly – use trans_identity(),
trans_translate(), trans_rotate(), trans_scale(),
trans_reflect(), trans_shear(), or the general-purpose
trans_affine() instead.
Usage
trans(matrix = integer(0))Details
Every drawable carries a trans property (default trans_identity())
that's applied to its computed points as the very last step – see
drawable's trans documentation.
Two trans objects combine with +: t1 + t2 produces a new trans
whose effect is "apply t1 first, then t2" – see trans_translate()'s
Details for the composition order convention and a worked example.
Composing a trans with a trans_warp (a non-rigid, noise-based
deformation) or a trans_fn (a non-rigid deformation from an
arbitrary caller-supplied function) – neither of which can be
represented as a matrix – instead produces a trans_chain – see
there.
See also
Other transform helpers:
trans_affine(),
trans_chain(),
trans_fn(),
trans_identity(),
trans_reflect(),
trans_rotate(),
trans_scale(),
trans_shear(),
trans_translate(),
trans_warp()
Examples
trans_identity()
#> <sketchpad::trans>
#> @ matrix: num [1:3, 1:3] 1 0 0 0 1 0 0 0 1
trans_translate(1, 0) + trans_rotate(pi / 4)
#> <sketchpad::trans>
#> @ matrix: num [1:3, 1:3] 0.707 0.707 0 -0.707 0.707 ...
# overlay a shape's original outline (faded) with a transformed copy
# (solid) to see a trans's effect directly
original <- shape_rectangle(
width = 1.5,
height = 0.6,
fill_alpha = 0.3,
color_alpha = 0.3
)
draw(sketch() + original + (original + trans_rotate(pi / 6)))